Line data Source code
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 : #include <vcl/svapp.hxx>
22 :
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>
43 :
44 : #include <svx/svdoutl.hxx>
45 :
46 : #include <sfx2/fcontnr.hxx>
47 :
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"
70 :
71 : using namespace sd;
72 : #define DrawDocShell
73 : #include "sdslots.hxx"
74 :
75 1247 : SFX_IMPL_SUPERCLASS_INTERFACE(DrawDocShell, SfxObjectShell);
76 :
77 21 : void DrawDocShell::InitInterface_Impl()
78 : {
79 21 : GetStaticInterface()->RegisterChildWindow(SvxSearchDialogWrapper::GetChildWindowId());
80 21 : }
81 :
82 : namespace sd {
83 :
84 : /**
85 : * slotmaps and definitions of SFX
86 : */
87 8711 : TYPEINIT1( DrawDocShell, SfxObjectShell );
88 :
89 10917 : SFX_IMPL_OBJECTFACTORY(
90 : DrawDocShell,
91 : SvGlobalName(SO3_SIMPRESS_CLASSID),
92 : SfxObjectShellFlags::STD_NORMAL,
93 : "simpress" )
94 :
95 318 : void DrawDocShell::Construct( bool bClipboard )
96 : {
97 318 : mbInDestruction = false;
98 318 : SetSlotFilter(); // setzt Filter zurueck
99 :
100 318 : mbOwnDocument = mpDoc == 0;
101 318 : if( mbOwnDocument )
102 318 : mpDoc = new SdDrawDocument(meDocType, this);
103 :
104 : // The document has been created so we can call UpdateRefDevice() to set
105 : // the document's ref device.
106 318 : UpdateRefDevice();
107 :
108 318 : SetBaseModel( new SdXImpressDocument( this, bClipboard ) );
109 318 : SetPool( &mpDoc->GetItemPool() );
110 318 : mpUndoManager = new sd::UndoManager;
111 318 : mpDoc->SetSdrUndoManager( mpUndoManager );
112 318 : mpDoc->SetSdrUndoFactory( new sd::UndoFactory );
113 318 : UpdateTablePointers();
114 318 : SetStyleFamily(5); //CL: actually SFX_STYLE_FAMILY_PSEUDO
115 318 : }
116 :
117 127 : 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 127 : mbNewDocument( true )
131 : {
132 127 : Construct( eMode == SfxObjectCreateMode::INTERNAL );
133 127 : }
134 :
135 191 : 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 191 : mbNewDocument( true )
147 : {
148 191 : Construct( false );
149 191 : }
150 :
151 0 : 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 0 : mbNewDocument( true )
165 : {
166 0 : Construct( eMode == SfxObjectCreateMode::INTERNAL );
167 0 : }
168 :
169 1068 : DrawDocShell::~DrawDocShell()
170 : {
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 313 : Broadcast(SfxSimpleHint(SFX_HINT_DYING));
176 :
177 313 : mbInDestruction = true;
178 :
179 313 : SetDocShellFunction(0);
180 :
181 313 : delete mpFontList;
182 :
183 313 : if( mpDoc )
184 313 : mpDoc->SetSdrUndoManager( 0 );
185 313 : delete mpUndoManager;
186 :
187 313 : if (mbOwnPrinter)
188 15 : mpPrinter.disposeAndClear();
189 :
190 313 : if( mbOwnDocument )
191 313 : delete mpDoc;
192 :
193 : // that the navigator get informed about the disappearance of the document
194 313 : SfxBoolItem aItem(SID_NAVIGATOR_INIT, true);
195 313 : SfxViewFrame* pFrame = mpViewShell ? mpViewShell->GetFrame() : GetFrame();
196 :
197 313 : if( !pFrame )
198 313 : pFrame = SfxViewFrame::GetFirst( this );
199 :
200 313 : if( pFrame )
201 : pFrame->GetDispatcher()->Execute(
202 0 : SID_NAVIGATOR_INIT, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD, &aItem, 0L);
203 755 : }
204 :
205 3 : void DrawDocShell::GetState(SfxItemSet &rSet)
206 : {
207 :
208 3 : SfxWhichIter aIter( rSet );
209 3 : sal_uInt16 nWhich = aIter.FirstWhich();
210 :
211 9 : while ( nWhich )
212 : {
213 3 : sal_uInt16 nSlotId = SfxItemPool::IsWhich(nWhich)
214 0 : ? GetPool().GetSlotId(nWhich)
215 3 : : nWhich;
216 :
217 3 : switch ( nSlotId )
218 : {
219 : case SID_SEARCH_ITEM:
220 : {
221 0 : rSet.Put( *SD_MOD()->GetSearchItem() );
222 : }
223 0 : break;
224 :
225 : case SID_CLOSEDOC:
226 0 : GetSlotState(SID_CLOSEDOC, SfxObjectShell::GetInterface(), &rSet);
227 0 : break;
228 :
229 : case SID_SEARCH_OPTIONS:
230 : {
231 : SearchOptionFlags nOpt = SearchOptionFlags::SEARCH |
232 : SearchOptionFlags::WHOLE_WORDS |
233 : SearchOptionFlags::BACKWARDS |
234 : SearchOptionFlags::REG_EXP |
235 : SearchOptionFlags::EXACT |
236 0 : SearchOptionFlags::SIMILARITY |
237 0 : SearchOptionFlags::SELECTION;
238 :
239 0 : if (!IsReadOnly())
240 : {
241 0 : nOpt |= SearchOptionFlags::REPLACE;
242 0 : nOpt |= SearchOptionFlags::REPLACE_ALL;
243 : }
244 :
245 0 : rSet.Put(SfxUInt16Item(nWhich, static_cast<sal_uInt16>(nOpt)));
246 : }
247 0 : break;
248 :
249 : case SID_VERSION:
250 : {
251 0 : GetSlotState( SID_VERSION, SfxObjectShell::GetInterface(), &rSet );
252 : }
253 0 : break;
254 :
255 : case SID_CHINESE_CONVERSION:
256 : case SID_HANGUL_HANJA_CONVERSION:
257 : {
258 0 : rSet.Put(SfxVisibilityItem(nWhich, SvtCJKOptions().IsAnyEnabled()));
259 : }
260 0 : break;
261 : case SID_LANGUAGE_STATUS:
262 : {
263 : // Keeping this enabled for the time being
264 0 : rSet.Put(SfxVisibilityItem(nWhich, true));
265 : }
266 0 : break;
267 :
268 : default:
269 3 : break;
270 : }
271 3 : nWhich = aIter.NextWhich();
272 : }
273 :
274 3 : SfxViewFrame* pFrame = SfxViewFrame::Current();
275 :
276 3 : if (pFrame)
277 : {
278 3 : if (rSet.GetItemState(SID_RELOAD) != SfxItemState::UNKNOWN)
279 : {
280 : pFrame->GetSlotState(SID_RELOAD,
281 0 : pFrame->GetInterface(), &rSet);
282 : }
283 3 : }
284 3 : }
285 :
286 0 : void DrawDocShell::InPlaceActivate( bool bActive )
287 : {
288 0 : SfxViewFrame* pSfxViewFrame = SfxViewFrame::GetFirst(this, false);
289 0 : std::vector<FrameView*> &rViews = mpDoc->GetFrameViewList();
290 :
291 0 : if( !bActive )
292 : {
293 0 : std::vector<FrameView*>::iterator pIter;
294 0 : for ( pIter = rViews.begin(); pIter != rViews.end(); ++pIter )
295 0 : delete *pIter;
296 :
297 0 : rViews.clear();
298 :
299 0 : while (pSfxViewFrame)
300 : {
301 : // determine the number of FrameViews
302 0 : 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 0 : ViewShell* pViewSh = (pSfxViewSh && pSfxViewSh->IsA( TYPE(ViewShell) )) ? dynamic_cast<ViewShell*>(pSfxViewSh) : 0;
305 :
306 0 : if ( pViewSh && pViewSh->GetFrameView() )
307 : {
308 0 : pViewSh->WriteFrameViewData();
309 0 : rViews.push_back( new FrameView( mpDoc, pViewSh->GetFrameView() ) );
310 : }
311 :
312 0 : pSfxViewFrame = SfxViewFrame::GetNext(*pSfxViewFrame, this, false);
313 : }
314 : }
315 :
316 0 : SfxObjectShell::InPlaceActivate( bActive );
317 :
318 0 : if( bActive )
319 : {
320 0 : for( sal_uInt32 i = 0; pSfxViewFrame && (i < rViews.size()); i++ )
321 : {
322 : // determine the number of FrameViews
323 0 : 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 0 : ViewShell* pViewSh = (pSfxViewSh && pSfxViewSh->IsA( TYPE(ViewShell) )) ? dynamic_cast<ViewShell*>(pSfxViewSh) : 0;
326 :
327 0 : if ( pViewSh )
328 : {
329 0 : pViewSh->ReadFrameViewData( rViews[ i ] );
330 : }
331 :
332 0 : pSfxViewFrame = SfxViewFrame::GetNext(*pSfxViewFrame, this, false);
333 : }
334 : }
335 0 : }
336 :
337 120 : void DrawDocShell::Activate( bool bMDI)
338 : {
339 120 : if (bMDI)
340 : {
341 120 : ApplySlotFilter();
342 120 : mpDoc->StartOnlineSpelling();
343 : }
344 120 : }
345 :
346 120 : void DrawDocShell::Deactivate( bool )
347 : {
348 120 : }
349 :
350 15191 : ::svl::IUndoManager* DrawDocShell::GetUndoManager()
351 : {
352 15191 : return mpUndoManager;
353 : }
354 :
355 359 : void DrawDocShell::UpdateTablePointers()
356 : {
357 359 : PutItem( SvxColorListItem( mpDoc->GetColorList(), SID_COLOR_TABLE ) );
358 359 : PutItem( SvxGradientListItem( mpDoc->GetGradientList(), SID_GRADIENT_LIST ) );
359 359 : PutItem( SvxHatchListItem( mpDoc->GetHatchList(), SID_HATCH_LIST ) );
360 359 : PutItem( SvxBitmapListItem( mpDoc->GetBitmapList(), SID_BITMAP_LIST ) );
361 359 : PutItem( SvxDashListItem( mpDoc->GetDashList(), SID_DASH_LIST ) );
362 359 : PutItem( SvxLineEndListItem( mpDoc->GetLineEndList(), SID_LINEEND_LIST ) );
363 :
364 359 : UpdateFontList();
365 359 : }
366 :
367 0 : void DrawDocShell::CancelSearching()
368 : {
369 0 : if( dynamic_cast<FuSearch*>( mxDocShellFunction.get() ) )
370 : {
371 0 : SetDocShellFunction(0);
372 : }
373 0 : }
374 :
375 : /**
376 : * apply configured slot filters
377 : */
378 120 : void DrawDocShell::ApplySlotFilter() const
379 : {
380 120 : SfxViewShell* pTestViewShell = SfxViewShell::GetFirst();
381 :
382 366 : while( pTestViewShell )
383 : {
384 252 : if( pTestViewShell->GetObjectShell()
385 126 : == this
386 120 : && pTestViewShell->GetViewFrame()
387 246 : && pTestViewShell->GetViewFrame()->GetDispatcher() )
388 : {
389 120 : SfxDispatcher* pDispatcher = pTestViewShell->GetViewFrame()->GetDispatcher();
390 :
391 120 : if( mpFilterSIDs )
392 0 : pDispatcher->SetSlotFilter( mbFilterEnable ? SfxSlotFilterState::ENABLED : SfxSlotFilterState::DISABLED, mnFilterCount, mpFilterSIDs );
393 : else
394 120 : pDispatcher->SetSlotFilter();
395 :
396 120 : if( pDispatcher->GetBindings() )
397 120 : pDispatcher->GetBindings()->InvalidateAll( true );
398 : }
399 :
400 126 : pTestViewShell = SfxViewShell::GetNext( *pTestViewShell );
401 : }
402 120 : }
403 :
404 46983 : void DrawDocShell::SetModified( bool bSet /* = true */ )
405 : {
406 46983 : SfxObjectShell::SetModified( bSet );
407 :
408 : // change model state, too
409 : // only set the changed state if modification is enabled
410 46983 : if( IsEnableSetModified() )
411 : {
412 46468 : if ( mpDoc )
413 46468 : mpDoc->NbcSetChanged( bSet );
414 :
415 46468 : Broadcast( SfxSimpleHint( SFX_HINT_DOCCHANGED ) );
416 : }
417 46983 : }
418 :
419 : /**
420 : * Callback for ExecuteSpellPopup()
421 : */
422 : // ExecuteSpellPopup now handled by DrawDocShell. This is necessary
423 : // to get hands on the outliner and the text object.
424 0 : IMPL_LINK(DrawDocShell, OnlineSpellCallback, SpellCallbackInfo*, pInfo)
425 : {
426 0 : SdrObject* pObj = NULL;
427 0 : SdrOutliner* pOutl = NULL;
428 :
429 0 : if(GetViewShell())
430 : {
431 0 : pOutl = GetViewShell()->GetView()->GetTextEditOutliner();
432 0 : pObj = GetViewShell()->GetView()->GetTextEditObject();
433 : }
434 :
435 0 : mpDoc->ImpOnlineSpellCallback(pInfo, pObj, pOutl);
436 0 : return 0;
437 : }
438 :
439 44 : void DrawDocShell::ClearUndoBuffer()
440 : {
441 : // clear possible undo buffers of outliners
442 44 : SfxViewFrame* pSfxViewFrame = SfxViewFrame::GetFirst(this, false);
443 88 : while(pSfxViewFrame)
444 : {
445 0 : ViewShellBase* pViewShellBase = dynamic_cast< ViewShellBase* >( pSfxViewFrame->GetViewShell() );
446 0 : if( pViewShellBase )
447 : {
448 0 : ::boost::shared_ptr<ViewShell> pViewSh( pViewShellBase->GetMainViewShell() );
449 0 : if( pViewSh.get() )
450 : {
451 0 : ::sd::View* pView = pViewSh->GetView();
452 0 : if( pView )
453 : {
454 0 : pView->SdrEndTextEdit();
455 0 : sd::OutlineView* pOutlView = dynamic_cast< sd::OutlineView* >( pView );
456 0 : if( pOutlView )
457 : {
458 0 : pOutlView->GetOutliner().GetUndoManager().Clear();
459 : }
460 : }
461 0 : }
462 : }
463 0 : pSfxViewFrame = SfxViewFrame::GetNext(*pSfxViewFrame, this, false);
464 : }
465 :
466 44 : ::svl::IUndoManager* pUndoManager = GetUndoManager();
467 44 : if(pUndoManager && pUndoManager->GetUndoActionCount())
468 0 : pUndoManager->Clear();
469 44 : }
470 :
471 0 : void DrawDocShell::libreOfficeKitCallback(int nType, const char* pPayload) const
472 : {
473 0 : if (mpDoc)
474 0 : mpDoc->libreOfficeKitCallback(nType, pPayload);
475 0 : }
476 :
477 3985 : bool DrawDocShell::isTiledRendering() const
478 : {
479 3985 : if (!mpDoc)
480 0 : return false;
481 3985 : return mpDoc->isTiledRendering();
482 : }
483 :
484 :
485 :
486 66 : } // end of namespace sd
487 :
488 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|