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