1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sd.hxx"
26
27 #include "DrawDocShell.hxx"
28 #include <tools/pstm.hxx>
29 #include <vcl/svapp.hxx>
30
31 #include <sfx2/docfac.hxx>
32 #include <sfx2/objface.hxx>
33
34 #ifndef _SVXIDS_HRC
35 #include <svx/svxids.hrc>
36 #endif
37 #include <svl/srchitem.hxx>
38 #include <svx/srchdlg.hxx>
39 #include <editeng/flstitem.hxx>
40 #include <svl/eitem.hxx>
41 #include <svl/intitem.hxx>
42 #include <sfx2/printer.hxx>
43 #ifndef _SFX_DOCFILE_HXX //autogen
44 #include <sfx2/docfile.hxx>
45 #endif
46 #include <svx/drawitem.hxx>
47 #include <editeng/flstitem.hxx>
48 #include <svx/drawitem.hxx>
49 #include <svx/srchdlg.hxx>
50 #include <sfx2/dispatch.hxx>
51 #include <svl/whiter.hxx>
52 #include <svl/itempool.hxx>
53 #include <svtools/ctrltool.hxx>
54 #include <svtools/filter.hxx>
55 #ifndef _SO_CLSIDS_HXX
56 #include <sot/clsids.hxx>
57 #endif
58 #include <svl/cjkoptions.hxx>
59 #include <svl/visitem.hxx>
60
61 #include <svx/svdoutl.hxx>
62
63 #include <sfx2/fcontnr.hxx>
64
65 #include "app.hrc"
66 #include "app.hxx"
67 #include "strmname.h"
68 #include "stlpool.hxx"
69 #include "strings.hrc"
70 #include "View.hxx"
71 #include "drawdoc.hxx"
72 #include "sdpage.hxx"
73 #include "glob.hrc"
74 #include "res_bmp.hrc"
75 #include "fupoor.hxx"
76 #include "fusearch.hxx"
77 #include "ViewShell.hxx"
78 #include "sdresid.hxx"
79 #ifndef SD_FU_SLIDE_SHOW_DLG_HXX
80 #include "slideshow.hxx"
81 #endif
82 #include "drawview.hxx"
83 #ifndef SD_FRAMW_VIEW_HXX
84 #include "FrameView.hxx"
85 #endif
86 #include "unomodel.hxx"
87 #include "undo/undomanager.hxx"
88 #include "undo/undofactory.hxx"
89 #include "OutlineView.hxx"
90 #include "ViewShellBase.hxx"
91
92 using namespace sd;
93 #define DrawDocShell
94 #include "sdslots.hxx"
95
96 SFX_IMPL_INTERFACE(DrawDocShell, SfxObjectShell, SdResId(0))
97 {
98 SFX_CHILDWINDOW_REGISTRATION(SvxSearchDialogWrapper::GetChildWindowId());
99 SFX_CHILDWINDOW_REGISTRATION(SID_HYPERLINK_INSERT);
100 }
101
102
103 namespace sd {
104
105 #define POOL_BUFFER_SIZE (sal_uInt16)32768
106 #define BASIC_BUFFER_SIZE (sal_uInt16)8192
107 #define DOCUMENT_BUFFER_SIZE (sal_uInt16)32768
108
109
110 GraphicFilter* GetGrfFilter();
111
112 /*************************************************************************
113 |*
114 |* SFX-Slotmaps und -Definitionen
115 |*
116 \************************************************************************/
117 TYPEINIT1( DrawDocShell, SfxObjectShell );
118
119 SFX_IMPL_OBJECTFACTORY(
120 DrawDocShell,
121 SvGlobalName(SO3_SIMPRESS_CLASSID),
122 SFXOBJECTSHELL_STD_NORMAL,
123 "simpress" )
124
125 /*************************************************************************
126 |*
127 |* Construct
128 |*
129 \************************************************************************/
130
Construct(bool bClipboard)131 void DrawDocShell::Construct( bool bClipboard )
132 {
133 mbInDestruction = sal_False;
134 SetSlotFilter(); // setzt Filter zurueck
135
136 mbOwnDocument = mpDoc == 0;
137 if( mbOwnDocument )
138 mpDoc = new SdDrawDocument(meDocType, this);
139
140 // The document has been created so we can call UpdateRefDevice() to set
141 // the document's ref device.
142 UpdateRefDevice();
143
144 SetBaseModel( new SdXImpressDocument( this, bClipboard ) );
145 SetPool( &mpDoc->GetItemPool() );
146 mpUndoManager = new sd::UndoManager;
147 mpDoc->SetSdrUndoManager( mpUndoManager );
148 mpDoc->SetSdrUndoFactory( new sd::UndoFactory );
149 UpdateTablePointers();
150 SetStyleFamily(5); //CL: eigentlich SFX_STYLE_FAMILY_PSEUDO
151 }
152
153 /*************************************************************************
154 |*
155 |* Konstruktor 1
156 |*
157 \************************************************************************/
158
DrawDocShell(SfxObjectCreateMode eMode,sal_Bool bDataObject,DocumentType eDocumentType)159 DrawDocShell::DrawDocShell(SfxObjectCreateMode eMode,
160 sal_Bool bDataObject,
161 DocumentType eDocumentType) :
162 SfxObjectShell( eMode == SFX_CREATE_MODE_INTERNAL ? SFX_CREATE_MODE_EMBEDDED : eMode),
163 mpDoc(NULL),
164 mpUndoManager(NULL),
165 mpPrinter(NULL),
166 mpViewShell(NULL),
167 mpFontList(NULL),
168 meDocType(eDocumentType),
169 mpFilterSIDs(0),
170 mbSdDataObj(bDataObject),
171 mbOwnPrinter(sal_False),
172 mbNewDocument( sal_True )
173 {
174 Construct( eMode == SFX_CREATE_MODE_INTERNAL );
175 }
176
177 /*************************************************************************
178 |*
179 |* Konstruktor 2
180 |*
181 \************************************************************************/
182
DrawDocShell(const sal_uInt64 nModelCreationFlags,sal_Bool bDataObject,DocumentType eDocumentType)183 DrawDocShell::DrawDocShell( const sal_uInt64 nModelCreationFlags, sal_Bool bDataObject, DocumentType eDocumentType ) :
184 SfxObjectShell( nModelCreationFlags ),
185 mpDoc(NULL),
186 mpUndoManager(NULL),
187 mpPrinter(NULL),
188 mpViewShell(NULL),
189 mpFontList(NULL),
190 meDocType(eDocumentType),
191 mpFilterSIDs(0),
192 mbSdDataObj(bDataObject),
193 mbOwnPrinter(sal_False),
194 mbNewDocument( sal_True )
195 {
196 Construct( sal_False );
197 }
198
199 /*************************************************************************
200 |*
201 |* Konstruktor 3
202 |*
203 \************************************************************************/
204
DrawDocShell(SdDrawDocument * pDoc,SfxObjectCreateMode eMode,sal_Bool bDataObject,DocumentType eDocumentType)205 DrawDocShell::DrawDocShell(SdDrawDocument* pDoc, SfxObjectCreateMode eMode,
206 sal_Bool bDataObject,
207 DocumentType eDocumentType) :
208 SfxObjectShell(eMode == SFX_CREATE_MODE_INTERNAL ? SFX_CREATE_MODE_EMBEDDED : eMode),
209 mpDoc(pDoc),
210 mpUndoManager(NULL),
211 mpPrinter(NULL),
212 mpViewShell(NULL),
213 mpFontList(NULL),
214 meDocType(eDocumentType),
215 mpFilterSIDs(0),
216 mbSdDataObj(bDataObject),
217 mbOwnPrinter(sal_False),
218 mbNewDocument( sal_True )
219 {
220 Construct( eMode == SFX_CREATE_MODE_INTERNAL );
221 }
222
223 /*************************************************************************
224 |*
225 |* Destruktor
226 |*
227 \************************************************************************/
228
~DrawDocShell()229 DrawDocShell::~DrawDocShell()
230 {
231 // Tell all listeners that the doc shell is about to be
232 // destroyed. This has been introduced for the PreviewRenderer to
233 // free its view (that uses the item poll of the doc shell) but
234 // may be useful in other places as well.
235 Broadcast(SfxSimpleHint(SFX_HINT_DYING));
236
237 mbInDestruction = sal_True;
238
239 SetDocShellFunction(0);
240
241 delete mpFontList;
242
243 if( mpDoc )
244 mpDoc->SetSdrUndoManager( 0 );
245 delete mpUndoManager;
246
247 if (mbOwnPrinter)
248 delete mpPrinter;
249
250 if( mbOwnDocument )
251 delete mpDoc;
252
253 // damit der Navigator das Verschwinden des Dokuments mitbekommt
254 SfxBoolItem aItem(SID_NAVIGATOR_INIT, sal_True);
255 SfxViewFrame* pFrame = mpViewShell ? mpViewShell->GetFrame() : GetFrame();
256
257 if( !pFrame )
258 pFrame = SfxViewFrame::GetFirst( this );
259
260 if( pFrame )
261 pFrame->GetDispatcher()->Execute(
262 SID_NAVIGATOR_INIT, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD, &aItem, 0L);
263 }
264
265 /*************************************************************************
266 |*
267 |* Slot-Stati setzen
268 |*
269 \************************************************************************/
270
GetState(SfxItemSet & rSet)271 void DrawDocShell::GetState(SfxItemSet &rSet)
272 {
273
274 SfxWhichIter aIter( rSet );
275 sal_uInt16 nWhich = aIter.FirstWhich();
276
277 while ( nWhich )
278 {
279 sal_uInt16 nSlotId = SfxItemPool::IsWhich(nWhich)
280 ? GetPool().GetSlotId(nWhich)
281 : nWhich;
282
283 switch ( nSlotId )
284 {
285 case SID_SEARCH_ITEM:
286 {
287 rSet.Put( *SD_MOD()->GetSearchItem() );
288 }
289 break;
290
291 case SID_CLOSEDOC:
292 {
293 sal_Bool bDisabled = sal_False;
294 if (bDisabled)
295 {
296 rSet.DisableItem(SID_CLOSEDOC);
297 }
298 else
299 {
300 GetSlotState(SID_CLOSEDOC, SfxObjectShell::GetInterface(), &rSet);
301 }
302 }
303 break;
304
305 case SID_SEARCH_OPTIONS:
306 {
307 sal_uInt16 nOpt = SEARCH_OPTIONS_SEARCH |
308 SEARCH_OPTIONS_WHOLE_WORDS |
309 SEARCH_OPTIONS_BACKWARDS |
310 SEARCH_OPTIONS_REG_EXP |
311 SEARCH_OPTIONS_EXACT |
312 SEARCH_OPTIONS_SIMILARITY |
313 SEARCH_OPTIONS_SELECTION;
314
315 if (!IsReadOnly())
316 {
317 nOpt |= SEARCH_OPTIONS_REPLACE;
318 nOpt |= SEARCH_OPTIONS_REPLACE_ALL;
319 }
320
321 rSet.Put(SfxUInt16Item(nWhich, nOpt));
322 }
323 break;
324
325 case SID_VERSION:
326 {
327 GetSlotState( SID_VERSION, SfxObjectShell::GetInterface(), &rSet );
328 }
329 break;
330
331 case SID_CHINESE_CONVERSION:
332 case SID_HANGUL_HANJA_CONVERSION:
333 {
334 rSet.Put(SfxVisibilityItem(nWhich, SvtCJKOptions().IsAnyEnabled()));
335 }
336 break;
337
338 default:
339 break;
340 }
341 nWhich = aIter.NextWhich();
342 }
343
344 SfxViewFrame* pFrame = SfxViewFrame::Current();
345
346 if (pFrame)
347 {
348 if (rSet.GetItemState(SID_RELOAD) != SFX_ITEM_UNKNOWN)
349 {
350 pFrame->GetSlotState(SID_RELOAD,
351 pFrame->GetInterface(), &rSet);
352 }
353 }
354 }
355
InPlaceActivate(sal_Bool bActive)356 void DrawDocShell::InPlaceActivate( sal_Bool bActive )
357 {
358 if( !bActive )
359 {
360 FrameView* pFrameView = NULL;
361 List* pFrameViewList = mpDoc->GetFrameViewList();
362
363 DBG_ASSERT( pFrameViewList, "No FrameViewList?" );
364 if( pFrameViewList )
365 {
366 sal_uInt32 i;
367 for ( i = 0; i < pFrameViewList->Count(); i++)
368 {
369 // Ggf. FrameViews loeschen
370 pFrameView = (FrameView*) pFrameViewList->GetObject(i);
371
372 if (pFrameView)
373 delete pFrameView;
374 }
375
376 pFrameViewList->Clear();
377
378 ViewShell* pViewSh = NULL;
379 SfxViewShell* pSfxViewSh = NULL;
380 SfxViewFrame* pSfxViewFrame = SfxViewFrame::GetFirst(this, false);
381
382 while (pSfxViewFrame)
383 {
384 // Anzahl FrameViews ermitteln
385 pSfxViewSh = pSfxViewFrame->GetViewShell();
386 pViewSh = PTR_CAST( ViewShell, pSfxViewSh );
387
388 if ( pViewSh && pViewSh->GetFrameView() )
389 {
390 pViewSh->WriteFrameViewData();
391 pFrameViewList->Insert( new FrameView( mpDoc, pViewSh->GetFrameView() ) );
392 }
393
394 pSfxViewFrame = SfxViewFrame::GetNext(*pSfxViewFrame, this, false);
395 }
396 }
397 }
398
399 SfxObjectShell::InPlaceActivate( bActive );
400
401 if( bActive )
402 {
403 List* pFrameViewList = mpDoc->GetFrameViewList();
404
405 DBG_ASSERT( pFrameViewList, "No FrameViewList?" );
406 if( pFrameViewList )
407 {
408 ViewShell* pViewSh = NULL;
409 SfxViewShell* pSfxViewSh = NULL;
410 SfxViewFrame* pSfxViewFrame = SfxViewFrame::GetFirst(this, false);
411
412 sal_uInt32 i;
413 for( i = 0; pSfxViewFrame && (i < pFrameViewList->Count()); i++ )
414 {
415 // Anzahl FrameViews ermitteln
416 pSfxViewSh = pSfxViewFrame->GetViewShell();
417 pViewSh = PTR_CAST( ViewShell, pSfxViewSh );
418
419 if ( pViewSh )
420 {
421 pViewSh->ReadFrameViewData( (FrameView*)pFrameViewList->GetObject(i) );
422 }
423
424 pSfxViewFrame = SfxViewFrame::GetNext(*pSfxViewFrame, this, false);
425 }
426 }
427 }
428 }
429
430 /*************************************************************************
431 |*
432 |* SFX-Aktivierung
433 |*
434 \************************************************************************/
435
Activate(sal_Bool bMDI)436 void DrawDocShell::Activate( sal_Bool bMDI)
437 {
438 if (bMDI)
439 {
440 ApplySlotFilter();
441 mpDoc->StartOnlineSpelling();
442 }
443 }
444
445 /*************************************************************************
446 |*
447 |* SFX-Deaktivierung
448 |*
449 \************************************************************************/
450
Deactivate(sal_Bool)451 void DrawDocShell::Deactivate( sal_Bool )
452 {
453 }
454
455 /*************************************************************************
456 |*
457 |* SFX-Undomanager zurueckgeben
458 |*
459 \************************************************************************/
460
GetUndoManager()461 ::svl::IUndoManager* DrawDocShell::GetUndoManager()
462 {
463 return mpUndoManager;
464 }
465
466
467
468 /*************************************************************************
469 |*
470 |* Tabellenzeiger auffrischen
471 |*
472 \************************************************************************/
473
UpdateTablePointers()474 void DrawDocShell::UpdateTablePointers()
475 {
476 PutItem( SvxColorTableItem( mpDoc->GetColorTableFromSdrModel(), SID_COLOR_TABLE ) );
477 PutItem( SvxGradientListItem( mpDoc->GetGradientListFromSdrModel(), SID_GRADIENT_LIST ) );
478 PutItem( SvxHatchListItem( mpDoc->GetHatchListFromSdrModel(), SID_HATCH_LIST ) );
479 PutItem( SvxBitmapListItem( mpDoc->GetBitmapListFromSdrModel(), SID_BITMAP_LIST ) );
480 PutItem( SvxDashListItem( mpDoc->GetDashListFromSdrModel(), SID_DASH_LIST ) );
481 PutItem( SvxLineEndListItem( mpDoc->GetLineEndListFromSdrModel(), SID_LINEEND_LIST ) );
482
483 UpdateFontList();
484 }
485
486 /*************************************************************************
487 |*
488 |*
489 |*
490 \************************************************************************/
491
CancelSearching()492 void DrawDocShell::CancelSearching()
493 {
494 if( dynamic_cast<FuSearch*>( mxDocShellFunction.get() ) )
495 {
496 SetDocShellFunction(0);
497 }
498 }
499
500 /*************************************************************************
501 |*
502 |* den eingestellten SlotFilter anwenden
503 |*
504 \************************************************************************/
505
ApplySlotFilter() const506 void DrawDocShell::ApplySlotFilter() const
507 {
508 SfxViewShell* pTestViewShell = SfxViewShell::GetFirst();
509
510 while( pTestViewShell )
511 {
512 if( pTestViewShell->GetObjectShell()
513 == const_cast<DrawDocShell*>( this )
514 && pTestViewShell->GetViewFrame()
515 && pTestViewShell->GetViewFrame()->GetDispatcher() )
516 {
517 SfxDispatcher* pDispatcher = pTestViewShell->GetViewFrame()->GetDispatcher();
518
519 if( mpFilterSIDs )
520 pDispatcher->SetSlotFilter( mbFilterEnable, mnFilterCount, mpFilterSIDs );
521 else
522 pDispatcher->SetSlotFilter();
523
524 if( pDispatcher->GetBindings() )
525 pDispatcher->GetBindings()->InvalidateAll( sal_True );
526 }
527
528 pTestViewShell = SfxViewShell::GetNext( *pTestViewShell );
529 }
530 }
531
SetModified(sal_Bool bSet)532 void DrawDocShell::SetModified( sal_Bool bSet /* = sal_True */ )
533 {
534 SfxObjectShell::SetModified( bSet );
535
536 // #100237# change model state, too
537 // #103182# only set the changed state if modification is enabled
538 if( IsEnableSetModified() )
539 {
540 if ( mpDoc )
541 mpDoc->NbcSetChanged( bSet );
542
543 Broadcast( SfxSimpleHint( SFX_HINT_DOCCHANGED ) );
544 }
545 }
546
547 /*************************************************************************
548 |*
549 |* Callback fuer ExecuteSpellPopup()
550 |*
551 \************************************************************************/
552
553 // #91457# ExecuteSpellPopup now handled by DrawDocShell. This is necessary
554 // to get hands on the outliner and the text object.
IMPL_LINK(DrawDocShell,OnlineSpellCallback,SpellCallbackInfo *,pInfo)555 IMPL_LINK(DrawDocShell, OnlineSpellCallback, SpellCallbackInfo*, pInfo)
556 {
557 SdrObject* pObj = NULL;
558 SdrOutliner* pOutl = NULL;
559
560 if(GetViewShell())
561 {
562 pOutl = GetViewShell()->GetView()->GetTextEditOutliner();
563 pObj = GetViewShell()->GetView()->GetTextEditObject();
564 }
565
566 mpDoc->ImpOnlineSpellCallback(pInfo, pObj, pOutl);
567 return(0);
568 }
569
ClearUndoBuffer()570 void DrawDocShell::ClearUndoBuffer()
571 {
572 // clear possible undo buffers of outliners
573 SfxViewFrame* pSfxViewFrame = SfxViewFrame::GetFirst(this, false);
574 while(pSfxViewFrame)
575 {
576 ViewShellBase* pViewShellBase = dynamic_cast< ViewShellBase* >( pSfxViewFrame->GetViewShell() );
577 if( pViewShellBase )
578 {
579 ::boost::shared_ptr<ViewShell> pViewSh( pViewShellBase->GetMainViewShell() );
580 if( pViewSh.get() )
581 {
582 ::sd::View* pView = pViewSh->GetView();
583 if( pView )
584 {
585 pView->SdrEndTextEdit();
586 sd::OutlineView* pOutlView = dynamic_cast< sd::OutlineView* >( pView );
587 if( pOutlView )
588 {
589 SdrOutliner* pOutliner = pOutlView->GetOutliner();
590 if( pOutliner )
591 pOutliner->GetUndoManager().Clear();
592 }
593 }
594 }
595 }
596 pSfxViewFrame = SfxViewFrame::GetNext(*pSfxViewFrame, this, false);
597 }
598
599 ::svl::IUndoManager* pUndoManager = GetUndoManager();
600 if(pUndoManager && pUndoManager->GetUndoActionCount())
601 pUndoManager->Clear();
602 }
603
604 } // end of namespace sd
605