merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / docshell / docshell.cxx
blob1ecfaa6ab208614a6a57f3de0680f0b39a6f1743
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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>
41 #ifndef _SVXIDS_HRC
42 #include <svx/svxids.hrc>
43 #endif
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>
52 #endif
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>
64 #endif
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>
73 #include "app.hrc"
74 #include "app.hxx"
75 #include "strmname.h"
76 #include "stlpool.hxx"
77 #include "strings.hrc"
78 #include "View.hxx"
79 #include "drawdoc.hxx"
80 #include "sdpage.hxx"
81 #include "glob.hrc"
82 #include "res_bmp.hrc"
83 #include "fupoor.hxx"
84 #include "fusearch.hxx"
85 #include "ViewShell.hxx"
86 #include "sdresid.hxx"
87 #ifndef SD_FU_SLIDE_SHOW_DLG_HXX
88 #include "slideshow.hxx"
89 #endif
90 #include "drawview.hxx"
91 #ifndef SD_FRAMW_VIEW_HXX
92 #include "FrameView.hxx"
93 #endif
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"
101 using namespace sd;
102 #define DrawDocShell
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);
112 namespace sd {
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(
129 DrawDocShell,
130 SvGlobalName(SO3_SIMPRESS_CLASSID),
131 SFXOBJECTSHELL_STD_NORMAL,
132 "simpress" )
134 /*************************************************************************
136 |* Construct
138 \************************************************************************/
140 void DrawDocShell::Construct( bool bClipboard )
142 mbInDestruction = FALSE;
143 SetSlotFilter(); // setzt Filter zurueck
145 mbOwnDocument = mpDoc == 0;
146 if( mbOwnDocument )
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.
151 UpdateRefDevice();
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 /*************************************************************************
164 |* Konstruktor 1
166 \************************************************************************/
168 DrawDocShell::DrawDocShell(SfxObjectCreateMode eMode,
169 BOOL bDataObject,
170 DocumentType eDocumentType,BOOL bScriptSupport) :
171 SfxObjectShell( eMode == SFX_CREATE_MODE_INTERNAL ? SFX_CREATE_MODE_EMBEDDED : eMode),
172 mpFormatClipboard(new SdFormatClipboard()),
173 mpDoc(NULL),
174 mpUndoManager(NULL),
175 mpPrinter(NULL),
176 mpViewShell(NULL),
177 mpFontList(NULL),
178 meDocType(eDocumentType),
179 mpFilterSIDs(0),
180 mbSdDataObj(bDataObject),
181 mbOwnPrinter(FALSE),
182 mbNewDocument( sal_True )
184 if ( !bScriptSupport )
185 SetHasNoBasic();
186 Construct( eMode == SFX_CREATE_MODE_INTERNAL );
189 /*************************************************************************
191 |* Konstruktor 2
193 \************************************************************************/
195 DrawDocShell::DrawDocShell(SdDrawDocument* pDoc, SfxObjectCreateMode eMode,
196 BOOL bDataObject,
197 DocumentType eDocumentType) :
198 SfxObjectShell(eMode == SFX_CREATE_MODE_INTERNAL ? SFX_CREATE_MODE_EMBEDDED : eMode),
199 mpFormatClipboard(new SdFormatClipboard()),
200 mpDoc(pDoc),
201 mpUndoManager(NULL),
202 mpPrinter(NULL),
203 mpViewShell(NULL),
204 mpFontList(NULL),
205 meDocType(eDocumentType),
206 mpFilterSIDs(0),
207 mbSdDataObj(bDataObject),
208 mbOwnPrinter(FALSE),
209 mbNewDocument( sal_True )
211 Construct( eMode == SFX_CREATE_MODE_INTERNAL );
214 /*************************************************************************
216 |* Destruktor
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);
232 delete mpFontList;
234 if( mpDoc )
235 mpDoc->SetSdrUndoManager( 0 );
236 delete mpUndoManager;
238 if(mpFormatClipboard)
239 delete mpFormatClipboard;
241 if (mbOwnPrinter)
242 delete mpPrinter;
244 if( mbOwnDocument )
245 delete mpDoc;
247 // damit der Navigator das Verschwinden des Dokuments mitbekommt
248 SfxBoolItem aItem(SID_NAVIGATOR_INIT, TRUE);
249 SfxViewFrame* pFrame = mpViewShell ? mpViewShell->GetFrame() : GetFrame();
251 if( !pFrame )
252 pFrame = SfxViewFrame::GetFirst( this );
254 if( pFrame )
255 pFrame->GetDispatcher()->Execute(
256 SID_NAVIGATOR_INIT, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD, &aItem, 0L);
259 /*************************************************************************
261 |* Slot-Stati setzen
263 \************************************************************************/
265 void DrawDocShell::GetState(SfxItemSet &rSet)
268 SfxWhichIter aIter( rSet );
269 USHORT nWhich = aIter.FirstWhich();
271 while ( nWhich )
273 USHORT nSlotId = SfxItemPool::IsWhich(nWhich)
274 ? GetPool().GetSlotId(nWhich)
275 : nWhich;
277 switch ( nSlotId )
279 case SID_SEARCH_ITEM:
281 rSet.Put( *SD_MOD()->GetSearchItem() );
283 break;
285 case SID_CLOSEDOC:
287 BOOL bDisabled = FALSE;
288 if (bDisabled)
290 rSet.DisableItem(SID_CLOSEDOC);
292 else
294 GetSlotState(SID_CLOSEDOC, SfxObjectShell::GetInterface(), &rSet);
297 break;
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;
309 if (!IsReadOnly())
311 nOpt |= SEARCH_OPTIONS_REPLACE;
312 nOpt |= SEARCH_OPTIONS_REPLACE_ALL;
315 rSet.Put(SfxUInt16Item(nWhich, nOpt));
317 break;
319 case SID_VERSION:
321 GetSlotState( SID_VERSION, SfxObjectShell::GetInterface(), &rSet );
323 break;
325 case SID_CHINESE_CONVERSION:
326 case SID_HANGUL_HANJA_CONVERSION:
328 rSet.Put(SfxVisibilityItem(nWhich, SvtCJKOptions().IsAnyEnabled()));
330 break;
332 default:
333 break;
335 nWhich = aIter.NextWhich();
338 SfxViewFrame* pFrame = SfxViewFrame::Current();
340 if (pFrame)
342 if (rSet.GetItemState(SID_RELOAD) != SFX_ITEM_UNKNOWN)
344 pFrame->GetSlotState(SID_RELOAD,
345 pFrame->GetInterface(), &rSet);
350 void DrawDocShell::InPlaceActivate( BOOL bActive )
352 if( !bActive )
354 FrameView* pFrameView = NULL;
355 List* pFrameViewList = mpDoc->GetFrameViewList();
357 DBG_ASSERT( pFrameViewList, "No FrameViewList?" );
358 if( pFrameViewList )
360 sal_uInt32 i;
361 for ( i = 0; i < pFrameViewList->Count(); i++)
363 // Ggf. FrameViews loeschen
364 pFrameView = (FrameView*) pFrameViewList->GetObject(i);
366 if (pFrameView)
367 delete pFrameView;
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 );
395 if( bActive )
397 List* pFrameViewList = mpDoc->GetFrameViewList();
399 DBG_ASSERT( pFrameViewList, "No FrameViewList?" );
400 if( pFrameViewList )
402 ViewShell* pViewSh = NULL;
403 SfxViewShell* pSfxViewSh = NULL;
404 SfxViewFrame* pSfxViewFrame = SfxViewFrame::GetFirst(this, 0,false);
406 sal_uInt32 i;
407 for( i = 0; pSfxViewFrame && (i < pFrameViewList->Count()); i++ )
409 // Anzahl FrameViews ermitteln
410 pSfxViewSh = pSfxViewFrame->GetViewShell();
411 pViewSh = PTR_CAST( ViewShell, pSfxViewSh );
413 if ( pViewSh )
415 pViewSh->ReadFrameViewData( (FrameView*)pFrameViewList->GetObject(i) );
418 pSfxViewFrame = SfxViewFrame::GetNext(*pSfxViewFrame, this, 0,false);
424 /*************************************************************************
426 |* SFX-Aktivierung
428 \************************************************************************/
430 void DrawDocShell::Activate( BOOL bMDI)
432 if (bMDI)
434 ApplySlotFilter();
435 mpDoc->StartOnlineSpelling();
439 /*************************************************************************
441 |* SFX-Deaktivierung
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 ) );
477 UpdateFontList();
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();
513 if( mpFilterSIDs )
514 pDispatcher->SetSlotFilter( mbFilterEnable, mnFilterCount, mpFilterSIDs );
515 else
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() )
534 if ( mpDoc )
535 mpDoc->NbcSetChanged( bSet );
537 Broadcast( SfxSimpleHint( SFX_HINT_DOCCHANGED ) );
541 ::Window* DrawDocShell::GetWindow() const
543 SfxViewFrame* pFrame = GetFrame();
544 if( pFrame == NULL )
545 pFrame = SfxViewFrame::GetFirst( this );
547 if( pFrame )
548 return &(pFrame->GetWindow());
549 else
551 DBG_ASSERT( 0, "No active window for DrawDocShell found! (next gpf is caused by this assertion)" );
552 return NULL;
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;
569 if(GetViewShell())
571 pOutl = GetViewShell()->GetView()->GetTextEditOutliner();
572 pObj = GetViewShell()->GetView()->GetTextEditObject();
575 mpDoc->ImpOnlineSpellCallback(pInfo, pObj, pOutl);
576 return(0);
579 void DrawDocShell::ClearUndoBuffer()
581 // clear possible undo buffers of outliners
582 SfxViewFrame* pSfxViewFrame = SfxViewFrame::GetFirst(this, 0, false);
583 while(pSfxViewFrame)
585 ViewShellBase* pViewShellBase = dynamic_cast< ViewShellBase* >( pSfxViewFrame->GetViewShell() );
586 if( pViewShellBase )
588 ::boost::shared_ptr<ViewShell> pViewSh( pViewShellBase->GetMainViewShell() );
589 if( pViewSh.get() )
591 ::sd::View* pView = pViewSh->GetView();
592 if( pView )
594 pView->SdrEndTextEdit();
595 sd::OutlineView* pOutlView = dynamic_cast< sd::OutlineView* >( pView );
596 if( pOutlView )
598 SdrOutliner* pOutliner = pOutlView->GetOutliner();
599 if( pOutliner )
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