1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: docshell.cxx,v $
10 * $Revision: 1.48.54.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include "DrawDocShell.hxx"
35 #include <tools/pstm.hxx>
36 #include <vcl/svapp.hxx>
38 #include <sfx2/docfac.hxx>
39 #include <sfx2/objface.hxx>
42 #include <svx/svxids.hrc>
44 #include <sfx2/srchitem.hxx>
45 #include <svx/srchdlg.hxx>
46 #include <svx/flstitem.hxx>
47 #include <svtools/eitem.hxx>
48 #include <svtools/intitem.hxx>
49 #include <sfx2/printer.hxx>
50 #ifndef _SFX_DOCFILE_HXX //autogen
51 #include <sfx2/docfile.hxx>
53 #include <svx/drawitem.hxx>
54 #include <svx/flstitem.hxx>
55 #include <svx/drawitem.hxx>
56 #include <svx/srchdlg.hxx>
57 #include <sfx2/dispatch.hxx>
58 #include <svtools/whiter.hxx>
59 #include <svtools/itempool.hxx>
60 #include <svtools/ctrltool.hxx>
61 #include <svtools/filter.hxx>
62 #ifndef _SO_CLSIDS_HXX
63 #include <sot/clsids.hxx>
65 #include <sfx2/topfrm.hxx>
66 #include <svtools/cjkoptions.hxx>
67 #include <svtools/visitem.hxx>
69 #include <svx/svdoutl.hxx>
71 #include <sfx2/fcontnr.hxx>
76 #include "stlpool.hxx"
77 #include "strings.hrc"
79 #include "drawdoc.hxx"
82 #include "res_bmp.hrc"
84 #include "fusearch.hxx"
85 #include "ViewShell.hxx"
86 #include "sdresid.hxx"
87 #ifndef SD_FU_SLIDE_SHOW_DLG_HXX
88 #include "slideshow.hxx"
90 #include "drawview.hxx"
91 #ifndef SD_FRAMW_VIEW_HXX
92 #include "FrameView.hxx"
94 #include "unomodel.hxx"
95 #include "formatclipboard.hxx"
96 #include "undo/undomanager.hxx"
97 #include "undo/undofactory.hxx"
98 #include "OutlineView.hxx"
99 #include "ViewShellBase.hxx"
103 #include "sdslots.hxx"
105 SFX_IMPL_INTERFACE(DrawDocShell
, SfxObjectShell
, SdResId(0))
107 SFX_CHILDWINDOW_REGISTRATION(SvxSearchDialogWrapper::GetChildWindowId());
108 SFX_CHILDWINDOW_REGISTRATION(SID_HYPERLINK_INSERT
);
114 #define POOL_BUFFER_SIZE (USHORT)32768
115 #define BASIC_BUFFER_SIZE (USHORT)8192
116 #define DOCUMENT_BUFFER_SIZE (USHORT)32768
119 GraphicFilter
* GetGrfFilter();
121 /*************************************************************************
123 |* SFX-Slotmaps und -Definitionen
125 \************************************************************************/
126 TYPEINIT1( DrawDocShell
, SfxObjectShell
);
128 SFX_IMPL_OBJECTFACTORY(
130 SvGlobalName(SO3_SIMPRESS_CLASSID
),
131 SFXOBJECTSHELL_STD_NORMAL
,
134 /*************************************************************************
138 \************************************************************************/
140 void DrawDocShell::Construct( bool bClipboard
)
142 mbInDestruction
= FALSE
;
143 SetSlotFilter(); // setzt Filter zurueck
145 mbOwnDocument
= mpDoc
== 0;
147 mpDoc
= new SdDrawDocument(meDocType
, this);
149 // The document has been created so we can call UpdateRefDevice() to set
150 // the document's ref device.
153 SetModel( new SdXImpressDocument( this, bClipboard
) );
154 SetPool( &mpDoc
->GetItemPool() );
155 mpUndoManager
= new sd::UndoManager
;
156 mpDoc
->SetSdrUndoManager( mpUndoManager
);
157 mpDoc
->SetSdrUndoFactory( new sd::UndoFactory
);
158 UpdateTablePointers();
159 SetStyleFamily(5); //CL: eigentlich SFX_STYLE_FAMILY_PSEUDO
162 /*************************************************************************
166 \************************************************************************/
168 DrawDocShell::DrawDocShell(SfxObjectCreateMode eMode
,
170 DocumentType eDocumentType
,BOOL bScriptSupport
) :
171 SfxObjectShell( eMode
== SFX_CREATE_MODE_INTERNAL
? SFX_CREATE_MODE_EMBEDDED
: eMode
),
172 mpFormatClipboard(new SdFormatClipboard()),
178 meDocType(eDocumentType
),
180 mbSdDataObj(bDataObject
),
182 mbNewDocument( sal_True
)
184 if ( !bScriptSupport
)
186 Construct( eMode
== SFX_CREATE_MODE_INTERNAL
);
189 /*************************************************************************
193 \************************************************************************/
195 DrawDocShell::DrawDocShell(SdDrawDocument
* pDoc
, SfxObjectCreateMode eMode
,
197 DocumentType eDocumentType
) :
198 SfxObjectShell(eMode
== SFX_CREATE_MODE_INTERNAL
? SFX_CREATE_MODE_EMBEDDED
: eMode
),
199 mpFormatClipboard(new SdFormatClipboard()),
205 meDocType(eDocumentType
),
207 mbSdDataObj(bDataObject
),
209 mbNewDocument( sal_True
)
211 Construct( eMode
== SFX_CREATE_MODE_INTERNAL
);
214 /*************************************************************************
218 \************************************************************************/
220 DrawDocShell::~DrawDocShell()
222 // Tell all listeners that the doc shell is about to be
223 // destroyed. This has been introduced for the PreviewRenderer to
224 // free its view (that uses the item poll of the doc shell) but
225 // may be usefull in other places as well.
226 Broadcast(SfxSimpleHint(SFX_HINT_DYING
));
228 mbInDestruction
= TRUE
;
230 SetDocShellFunction(0);
235 mpDoc
->SetSdrUndoManager( 0 );
236 delete mpUndoManager
;
238 if(mpFormatClipboard
)
239 delete mpFormatClipboard
;
247 // damit der Navigator das Verschwinden des Dokuments mitbekommt
248 SfxBoolItem
aItem(SID_NAVIGATOR_INIT
, TRUE
);
249 SfxViewFrame
* pFrame
= mpViewShell
? mpViewShell
->GetFrame() : GetFrame();
252 pFrame
= SfxViewFrame::GetFirst( this );
255 pFrame
->GetDispatcher()->Execute(
256 SID_NAVIGATOR_INIT
, SFX_CALLMODE_ASYNCHRON
| SFX_CALLMODE_RECORD
, &aItem
, 0L);
259 /*************************************************************************
263 \************************************************************************/
265 void DrawDocShell::GetState(SfxItemSet
&rSet
)
268 SfxWhichIter
aIter( rSet
);
269 USHORT nWhich
= aIter
.FirstWhich();
273 USHORT nSlotId
= SfxItemPool::IsWhich(nWhich
)
274 ? GetPool().GetSlotId(nWhich
)
279 case SID_SEARCH_ITEM
:
281 rSet
.Put( *SD_MOD()->GetSearchItem() );
287 BOOL bDisabled
= FALSE
;
290 rSet
.DisableItem(SID_CLOSEDOC
);
294 GetSlotState(SID_CLOSEDOC
, SfxObjectShell::GetInterface(), &rSet
);
299 case SID_SEARCH_OPTIONS
:
301 UINT16 nOpt
= SEARCH_OPTIONS_SEARCH
|
302 SEARCH_OPTIONS_WHOLE_WORDS
|
303 SEARCH_OPTIONS_BACKWARDS
|
304 SEARCH_OPTIONS_REG_EXP
|
305 SEARCH_OPTIONS_EXACT
|
306 SEARCH_OPTIONS_SIMILARITY
|
307 SEARCH_OPTIONS_SELECTION
;
311 nOpt
|= SEARCH_OPTIONS_REPLACE
;
312 nOpt
|= SEARCH_OPTIONS_REPLACE_ALL
;
315 rSet
.Put(SfxUInt16Item(nWhich
, nOpt
));
321 GetSlotState( SID_VERSION
, SfxObjectShell::GetInterface(), &rSet
);
325 case SID_CHINESE_CONVERSION
:
326 case SID_HANGUL_HANJA_CONVERSION
:
328 rSet
.Put(SfxVisibilityItem(nWhich
, SvtCJKOptions().IsAnyEnabled()));
335 nWhich
= aIter
.NextWhich();
338 SfxViewFrame
* pFrame
= SfxViewFrame::Current();
342 if (rSet
.GetItemState(SID_RELOAD
) != SFX_ITEM_UNKNOWN
)
344 pFrame
->GetSlotState(SID_RELOAD
,
345 pFrame
->GetInterface(), &rSet
);
350 void DrawDocShell::InPlaceActivate( BOOL bActive
)
354 FrameView
* pFrameView
= NULL
;
355 List
* pFrameViewList
= mpDoc
->GetFrameViewList();
357 DBG_ASSERT( pFrameViewList
, "No FrameViewList?" );
361 for ( i
= 0; i
< pFrameViewList
->Count(); i
++)
363 // Ggf. FrameViews loeschen
364 pFrameView
= (FrameView
*) pFrameViewList
->GetObject(i
);
370 pFrameViewList
->Clear();
372 ViewShell
* pViewSh
= NULL
;
373 SfxViewShell
* pSfxViewSh
= NULL
;
374 SfxViewFrame
* pSfxViewFrame
= SfxViewFrame::GetFirst(this, 0, false);
376 while (pSfxViewFrame
)
378 // Anzahl FrameViews ermitteln
379 pSfxViewSh
= pSfxViewFrame
->GetViewShell();
380 pViewSh
= PTR_CAST( ViewShell
, pSfxViewSh
);
382 if ( pViewSh
&& pViewSh
->GetFrameView() )
384 pViewSh
->WriteFrameViewData();
385 pFrameViewList
->Insert( new FrameView( mpDoc
, pViewSh
->GetFrameView() ) );
388 pSfxViewFrame
= SfxViewFrame::GetNext(*pSfxViewFrame
, this, 0, false);
393 SfxObjectShell::InPlaceActivate( bActive
);
397 List
* pFrameViewList
= mpDoc
->GetFrameViewList();
399 DBG_ASSERT( pFrameViewList
, "No FrameViewList?" );
402 ViewShell
* pViewSh
= NULL
;
403 SfxViewShell
* pSfxViewSh
= NULL
;
404 SfxViewFrame
* pSfxViewFrame
= SfxViewFrame::GetFirst(this, 0,false);
407 for( i
= 0; pSfxViewFrame
&& (i
< pFrameViewList
->Count()); i
++ )
409 // Anzahl FrameViews ermitteln
410 pSfxViewSh
= pSfxViewFrame
->GetViewShell();
411 pViewSh
= PTR_CAST( ViewShell
, pSfxViewSh
);
415 pViewSh
->ReadFrameViewData( (FrameView
*)pFrameViewList
->GetObject(i
) );
418 pSfxViewFrame
= SfxViewFrame::GetNext(*pSfxViewFrame
, this, 0,false);
424 /*************************************************************************
428 \************************************************************************/
430 void DrawDocShell::Activate( BOOL bMDI
)
435 mpDoc
->StartOnlineSpelling();
439 /*************************************************************************
443 \************************************************************************/
445 void DrawDocShell::Deactivate( BOOL
)
449 /*************************************************************************
451 |* SFX-Undomanager zurueckgeben
453 \************************************************************************/
455 SfxUndoManager
* DrawDocShell::GetUndoManager()
457 return mpUndoManager
;
462 /*************************************************************************
464 |* Tabellenzeiger auffrischen
466 \************************************************************************/
468 void DrawDocShell::UpdateTablePointers()
470 PutItem( SvxColorTableItem( mpDoc
->GetColorTable(), SID_COLOR_TABLE
) );
471 PutItem( SvxGradientListItem( mpDoc
->GetGradientList(), SID_GRADIENT_LIST
) );
472 PutItem( SvxHatchListItem( mpDoc
->GetHatchList(), SID_HATCH_LIST
) );
473 PutItem( SvxBitmapListItem( mpDoc
->GetBitmapList(), SID_BITMAP_LIST
) );
474 PutItem( SvxDashListItem( mpDoc
->GetDashList(), SID_DASH_LIST
) );
475 PutItem( SvxLineEndListItem( mpDoc
->GetLineEndList(), SID_LINEEND_LIST
) );
480 /*************************************************************************
484 \************************************************************************/
486 void DrawDocShell::CancelSearching()
488 if( dynamic_cast<FuSearch
*>( mxDocShellFunction
.get() ) )
490 SetDocShellFunction(0);
494 /*************************************************************************
496 |* den eingestellten SlotFilter anwenden
498 \************************************************************************/
500 void DrawDocShell::ApplySlotFilter() const
502 SfxViewShell
* pTestViewShell
= SfxViewShell::GetFirst();
504 while( pTestViewShell
)
506 if( pTestViewShell
->GetObjectShell()
507 == const_cast<DrawDocShell
*>( this )
508 && pTestViewShell
->GetViewFrame()
509 && pTestViewShell
->GetViewFrame()->GetDispatcher() )
511 SfxDispatcher
* pDispatcher
= pTestViewShell
->GetViewFrame()->GetDispatcher();
514 pDispatcher
->SetSlotFilter( mbFilterEnable
, mnFilterCount
, mpFilterSIDs
);
516 pDispatcher
->SetSlotFilter();
518 if( pDispatcher
->GetBindings() )
519 pDispatcher
->GetBindings()->InvalidateAll( TRUE
);
522 pTestViewShell
= SfxViewShell::GetNext( *pTestViewShell
);
526 void DrawDocShell::SetModified( BOOL bSet
/* = TRUE */ )
528 SfxObjectShell::SetModified( bSet
);
530 // #100237# change model state, too
531 // #103182# only set the changed state if modification is enabled
532 if( IsEnableSetModified() )
535 mpDoc
->NbcSetChanged( bSet
);
537 Broadcast( SfxSimpleHint( SFX_HINT_DOCCHANGED
) );
541 ::Window
* DrawDocShell::GetWindow() const
543 SfxViewFrame
* pFrame
= GetFrame();
545 pFrame
= SfxViewFrame::GetFirst( this );
548 return &(pFrame
->GetWindow());
551 DBG_ASSERT( 0, "No active window for DrawDocShell found! (next gpf is caused by this assertion)" );
556 /*************************************************************************
558 |* Callback fuer ExecuteSpellPopup()
560 \************************************************************************/
562 // #91457# ExecuteSpellPopup now handled by DrawDocShell. This is necessary
563 // to get hands on the outliner and the text object.
564 IMPL_LINK(DrawDocShell
, OnlineSpellCallback
, SpellCallbackInfo
*, pInfo
)
566 SdrObject
* pObj
= NULL
;
567 SdrOutliner
* pOutl
= NULL
;
571 pOutl
= GetViewShell()->GetView()->GetTextEditOutliner();
572 pObj
= GetViewShell()->GetView()->GetTextEditObject();
575 mpDoc
->ImpOnlineSpellCallback(pInfo
, pObj
, pOutl
);
579 void DrawDocShell::ClearUndoBuffer()
581 // clear possible undo buffers of outliners
582 SfxViewFrame
* pSfxViewFrame
= SfxViewFrame::GetFirst(this, 0, false);
585 ViewShellBase
* pViewShellBase
= dynamic_cast< ViewShellBase
* >( pSfxViewFrame
->GetViewShell() );
588 ::boost::shared_ptr
<ViewShell
> pViewSh( pViewShellBase
->GetMainViewShell() );
591 ::sd::View
* pView
= pViewSh
->GetView();
594 pView
->SdrEndTextEdit();
595 sd::OutlineView
* pOutlView
= dynamic_cast< sd::OutlineView
* >( pView
);
598 SdrOutliner
* pOutliner
= pOutlView
->GetOutliner();
600 pOutliner
->GetUndoManager().Clear();
605 pSfxViewFrame
= SfxViewFrame::GetNext(*pSfxViewFrame
, this, 0, false);
608 SfxUndoManager
* pUndoManager
= GetUndoManager();
609 if(pUndoManager
&& pUndoManager
->GetUndoActionCount())
610 pUndoManager
->Clear();
613 } // end of namespace sd