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