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 <com/sun/star/document/PrinterIndependentLayout.hpp>
23 : #include <tools/urlobj.hxx>
24 : #include <sfx2/progress.hxx>
25 : #include <vcl/waitobj.hxx>
26 : #include <svx/svxids.hrc>
27 : #include <editeng/flstitem.hxx>
28 : #include <editeng/eeitem.hxx>
29 : #include <svl/aeitem.hxx>
30 : #include <svl/flagitem.hxx>
31 : #include <sot/storage.hxx>
32 : #include <sfx2/dinfdlg.hxx>
33 : #include <sfx2/docfile.hxx>
34 : #include <sfx2/docfilt.hxx>
35 : #include <sfx2/dispatch.hxx>
36 : #include <svx/svdotext.hxx>
37 : #include <svl/style.hxx>
38 : #include <sfx2/printer.hxx>
39 : #include <svtools/ctrltool.hxx>
40 : #include <svtools/sfxecode.hxx>
41 : #include <comphelper/classids.hxx>
42 : #include <sot/formats.hxx>
43 : #include <sfx2/request.hxx>
44 : #include <unotools/fltrcfg.hxx>
45 : #include <sfx2/frame.hxx>
46 : #include <sfx2/viewfrm.hxx>
47 : #include <unotools/saveopt.hxx>
48 : #include <com/sun/star/drawing/XDrawPage.hpp>
49 : #include <com/sun/star/drawing/XDrawView.hpp>
50 : #include <comphelper/processfactory.hxx>
51 :
52 : #include "app.hrc"
53 : #include "glob.hrc"
54 : #include "strings.hrc"
55 : #include "strmname.h"
56 : #include "FrameView.hxx"
57 : #include "optsitem.hxx"
58 : #include "Outliner.hxx"
59 : #include "sdattr.hxx"
60 : #include "drawdoc.hxx"
61 : #include "ViewShell.hxx"
62 : #include "sdmod.hxx"
63 : #include "View.hxx"
64 : #include "sdpage.hxx"
65 : #include "sdresid.hxx"
66 : #include "DrawViewShell.hxx"
67 : #include "ViewShellBase.hxx"
68 : #include "Window.hxx"
69 : #include "sdmod.hxx"
70 : #include "OutlineViewShell.hxx"
71 : #include "sdxmlwrp.hxx"
72 : #include "sdpptwrp.hxx"
73 : #include "sdcgmfilter.hxx"
74 : #include "sdgrffilter.hxx"
75 : #include "sdhtmlfilter.hxx"
76 : #include "framework/FrameworkHelper.hxx"
77 :
78 : using namespace ::com::sun::star;
79 : using namespace ::com::sun::star::uno;
80 : using ::sd::framework::FrameworkHelper;
81 :
82 :
83 : namespace sd {
84 :
85 : /**
86 : * Creates (if necessary) and returns a SfxPrinter
87 : */
88 776 : SfxPrinter* DrawDocShell::GetPrinter(sal_Bool bCreate)
89 : {
90 776 : if (bCreate && !mpPrinter)
91 : {
92 : // create ItemSet with special pool area
93 0 : SfxItemSet* pSet = new SfxItemSet( GetPool(),
94 : SID_PRINTER_NOTFOUND_WARN, SID_PRINTER_NOTFOUND_WARN,
95 : SID_PRINTER_CHANGESTODOC, SID_PRINTER_CHANGESTODOC,
96 : ATTR_OPTIONS_PRINT, ATTR_OPTIONS_PRINT,
97 0 : 0 );
98 : // set PrintOptionsSet
99 : SdOptionsPrintItem aPrintItem( ATTR_OPTIONS_PRINT,
100 0 : SD_MOD()->GetSdOptions(mpDoc->GetDocumentType()));
101 0 : SfxFlagItem aFlagItem( SID_PRINTER_CHANGESTODOC );
102 0 : sal_uInt16 nFlags = 0;
103 :
104 0 : nFlags = (aPrintItem.GetOptionsPrint().IsWarningSize() ? SFX_PRINTER_CHG_SIZE : 0) |
105 0 : (aPrintItem.GetOptionsPrint().IsWarningOrientation() ? SFX_PRINTER_CHG_ORIENTATION : 0);
106 0 : aFlagItem.SetValue( nFlags );
107 :
108 0 : pSet->Put( aPrintItem );
109 0 : pSet->Put( SfxBoolItem( SID_PRINTER_NOTFOUND_WARN, aPrintItem.GetOptionsPrint().IsWarningPrinter() ) );
110 0 : pSet->Put( aFlagItem );
111 :
112 0 : mpPrinter = new SfxPrinter(pSet);
113 0 : mbOwnPrinter = sal_True;
114 :
115 : // set output quality
116 0 : sal_uInt16 nQuality = aPrintItem.GetOptionsPrint().GetOutputQuality();
117 :
118 0 : sal_uLong nMode = DRAWMODE_DEFAULT;
119 :
120 0 : if( nQuality == 1 )
121 0 : nMode = DRAWMODE_GRAYLINE | DRAWMODE_GRAYFILL | DRAWMODE_GRAYTEXT | DRAWMODE_GRAYBITMAP | DRAWMODE_GRAYGRADIENT;
122 0 : else if( nQuality == 2 )
123 0 : nMode = DRAWMODE_BLACKLINE | DRAWMODE_WHITEFILL | DRAWMODE_BLACKTEXT | DRAWMODE_WHITEBITMAP | DRAWMODE_WHITEGRADIENT;
124 :
125 0 : mpPrinter->SetDrawMode( nMode );
126 :
127 0 : MapMode aMM (mpPrinter->GetMapMode());
128 0 : aMM.SetMapUnit(MAP_100TH_MM);
129 0 : mpPrinter->SetMapMode(aMM);
130 0 : UpdateRefDevice();
131 : }
132 776 : return mpPrinter;
133 : }
134 :
135 : /**
136 : * Set new SfxPrinter (transfer of ownership)
137 : */
138 2 : void DrawDocShell::SetPrinter(SfxPrinter *pNewPrinter)
139 : {
140 2 : if ( mpViewShell )
141 : {
142 0 : ::sd::View* pView = mpViewShell->GetView();
143 0 : if ( pView->IsTextEdit() )
144 0 : pView->SdrEndTextEdit();
145 : }
146 :
147 2 : if ( mpPrinter && mbOwnPrinter && (mpPrinter != pNewPrinter) )
148 : {
149 0 : delete mpPrinter;
150 : }
151 :
152 2 : mpPrinter = pNewPrinter;
153 2 : mbOwnPrinter = sal_True;
154 2 : if ( mpDoc->GetPrinterIndependentLayout() == ::com::sun::star::document::PrinterIndependentLayout::DISABLED )
155 1 : UpdateFontList();
156 2 : UpdateRefDevice();
157 2 : }
158 :
159 96 : void DrawDocShell::UpdateFontList()
160 : {
161 96 : delete mpFontList;
162 96 : OutputDevice* pRefDevice = NULL;
163 96 : if ( mpDoc->GetPrinterIndependentLayout() == ::com::sun::star::document::PrinterIndependentLayout::DISABLED )
164 1 : pRefDevice = GetPrinter(sal_True);
165 : else
166 95 : pRefDevice = SD_MOD()->GetVirtualRefDevice();
167 96 : mpFontList = new FontList( pRefDevice, NULL, sal_False );
168 96 : SvxFontListItem aFontListItem( mpFontList, SID_ATTR_CHAR_FONTLIST );
169 96 : PutItem( aFontListItem );
170 96 : }
171 :
172 0 : Printer* DrawDocShell::GetDocumentPrinter()
173 : {
174 0 : return GetPrinter(sal_False);
175 : }
176 :
177 0 : void DrawDocShell::OnDocumentPrinterChanged(Printer* pNewPrinter)
178 : {
179 : // if we already have a printer, see if its the same
180 0 : if( mpPrinter )
181 : {
182 : // easy case
183 0 : if( mpPrinter == pNewPrinter )
184 0 : return;
185 :
186 : // compare if its the same printer with the same job setup
187 0 : if( (mpPrinter->GetName() == pNewPrinter->GetName()) &&
188 0 : (mpPrinter->GetJobSetup() == pNewPrinter->GetJobSetup()))
189 0 : return;
190 : }
191 :
192 : // if (mpPrinter->IsA(SfxPrinter))
193 : {
194 : // Since we do not have RTTI we use a hard cast (...)
195 0 : SetPrinter((SfxPrinter*) pNewPrinter);
196 :
197 : // container owns printer
198 0 : mbOwnPrinter = sal_False;
199 : }
200 : }
201 :
202 187 : void DrawDocShell::UpdateRefDevice()
203 : {
204 187 : if( mpDoc )
205 : {
206 : // Determine the device for which the output will be formatted.
207 98 : OutputDevice* pRefDevice = NULL;
208 98 : switch (mpDoc->GetPrinterIndependentLayout())
209 : {
210 : case ::com::sun::star::document::PrinterIndependentLayout::DISABLED:
211 2 : pRefDevice = mpPrinter;
212 2 : break;
213 :
214 : case ::com::sun::star::document::PrinterIndependentLayout::ENABLED:
215 96 : pRefDevice = SD_MOD()->GetVirtualRefDevice();
216 96 : break;
217 :
218 : default:
219 : // We are confronted with an invalid or un-implemented
220 : // layout mode. Use the printer as formatting device
221 : // as a fall-back.
222 : DBG_ASSERT(false, "DrawDocShell::UpdateRefDevice(): Unexpected printer layout mode");
223 :
224 0 : pRefDevice = mpPrinter;
225 0 : break;
226 : }
227 98 : mpDoc->SetRefDevice( pRefDevice );
228 :
229 98 : ::sd::Outliner* pOutl = mpDoc->GetOutliner( sal_False );
230 :
231 98 : if( pOutl )
232 0 : pOutl->SetRefDevice( pRefDevice );
233 :
234 98 : ::sd::Outliner* pInternalOutl = mpDoc->GetInternalOutliner( sal_False );
235 :
236 98 : if( pInternalOutl )
237 9 : pInternalOutl->SetRefDevice( pRefDevice );
238 : }
239 187 : }
240 :
241 : /**
242 : * Creates new document, opens streams
243 : */
244 77 : sal_Bool DrawDocShell::InitNew( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage )
245 : {
246 77 : sal_Bool bRet = sal_False;
247 :
248 77 : bRet = SfxObjectShell::InitNew( xStorage );
249 :
250 77 : Rectangle aVisArea( Point(0, 0), Size(14100, 10000) );
251 77 : SetVisArea(aVisArea);
252 :
253 77 : if (bRet)
254 : {
255 77 : if( !mbSdDataObj )
256 77 : mpDoc->NewOrLoadCompleted(NEW_DOC); // otherwise calling
257 : // NewOrLoadCompleted(NEW_LOADED) in
258 : // SdDrawDocument::AllocModel()
259 : }
260 77 : return bRet;
261 : }
262 :
263 : /**
264 : * loads pools and document
265 : */
266 6 : sal_Bool DrawDocShell::Load( SfxMedium& rMedium )
267 : {
268 6 : mbNewDocument = sal_False;
269 :
270 6 : sal_Bool bRet = sal_False;
271 6 : bool bStartPresentation = false;
272 6 : ErrCode nError = ERRCODE_NONE;
273 :
274 6 : SfxItemSet* pSet = rMedium.GetItemSet();
275 :
276 :
277 6 : if( pSet )
278 : {
279 6 : if( ( SFX_ITEM_SET == pSet->GetItemState(SID_PREVIEW ) ) && ( (SfxBoolItem&) ( pSet->Get( SID_PREVIEW ) ) ).GetValue() )
280 : {
281 0 : mpDoc->SetStarDrawPreviewMode( sal_True );
282 : }
283 :
284 6 : if( SFX_ITEM_SET == pSet->GetItemState(SID_DOC_STARTPRESENTATION)&&
285 0 : ( (SfxBoolItem&) ( pSet->Get( SID_DOC_STARTPRESENTATION ) ) ).GetValue() )
286 : {
287 0 : bStartPresentation = true;
288 0 : mpDoc->SetStartWithPresentation( true );
289 : }
290 : }
291 :
292 6 : bRet = SfxObjectShell::Load( rMedium );
293 6 : if( bRet )
294 : {
295 6 : bRet = SdXMLFilter( rMedium, *this, sal_True, SDXMLMODE_Normal, SotStorage::GetVersion( rMedium.GetStorage() ) ).Import( nError );
296 : }
297 :
298 6 : if( bRet )
299 : {
300 6 : UpdateTablePointers();
301 :
302 : // If we're an embedded OLE object, use tight bounds
303 : // for our visArea. No point in showing the user lots of empty
304 : // space. Had to remove the check for empty VisArea below,
305 : // since XML load always sets a VisArea before.
306 : //TODO/LATER: looks a little bit strange!
307 6 : if( ( GetCreateMode() == SFX_CREATE_MODE_EMBEDDED ) && SfxObjectShell::GetVisArea( ASPECT_CONTENT ).IsEmpty() )
308 : {
309 0 : SdPage* pPage = mpDoc->GetSdPage( 0, PK_STANDARD );
310 :
311 0 : if( pPage )
312 0 : SetVisArea( Rectangle( pPage->GetAllObjBoundRect() ) );
313 : }
314 :
315 6 : FinishedLoading( SFX_LOADED_ALL );
316 :
317 6 : const INetURLObject aUrl;
318 6 : SfxObjectShell::SetAutoLoad( aUrl, 0, sal_False );
319 : }
320 : else
321 : {
322 0 : if( nError == ERRCODE_IO_BROKENPACKAGE )
323 0 : SetError( ERRCODE_IO_BROKENPACKAGE, OSL_LOG_PREFIX );
324 :
325 : // TODO/LATER: correct error handling?!
326 : //pStore->SetError( SVSTREAM_WRONGVERSION, OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ) );
327 : else
328 0 : SetError( ERRCODE_ABORT, OSL_LOG_PREFIX );
329 : }
330 :
331 : // tell SFX to change viewshell when in preview mode
332 6 : if( IsPreview() || bStartPresentation )
333 : {
334 0 : SfxItemSet *pMediumSet = GetMedium()->GetItemSet();
335 0 : if( pMediumSet )
336 0 : pMediumSet->Put( SfxUInt16Item( SID_VIEW_ID, bStartPresentation ? 1 : 5 ) );
337 : }
338 :
339 6 : return bRet;
340 : }
341 :
342 : /**
343 : * loads content for organizer
344 : */
345 0 : sal_Bool DrawDocShell::LoadFrom( SfxMedium& rMedium )
346 : {
347 0 : mbNewDocument = sal_False;
348 :
349 0 : WaitObject* pWait = NULL;
350 0 : if( mpViewShell )
351 0 : pWait = new WaitObject( (Window*) mpViewShell->GetActiveWindow() );
352 :
353 0 : sal_Bool bRet = sal_False;
354 :
355 0 : mpDoc->NewOrLoadCompleted( NEW_DOC );
356 0 : mpDoc->CreateFirstPages();
357 0 : mpDoc->StopWorkStartupDelay();
358 :
359 : // TODO/LATER: nobody is interested in the error code?!
360 0 : ErrCode nError = ERRCODE_NONE;
361 0 : bRet = SdXMLFilter( rMedium, *this, sal_True, SDXMLMODE_Organizer, SotStorage::GetVersion( rMedium.GetStorage() ) ).Import( nError );
362 :
363 :
364 : // tell SFX to change viewshell when in preview mode
365 0 : if( IsPreview() )
366 : {
367 0 : SfxItemSet *pSet = GetMedium()->GetItemSet();
368 :
369 0 : if( pSet )
370 0 : pSet->Put( SfxUInt16Item( SID_VIEW_ID, 5 ) );
371 : }
372 :
373 0 : delete pWait;
374 :
375 0 : return bRet;
376 : }
377 :
378 : /**
379 : * load from 3rd party format
380 : */
381 7 : sal_Bool DrawDocShell::ImportFrom( SfxMedium &rMedium, bool bInsert )
382 : {
383 7 : const sal_Bool bRet=SfxObjectShell::ImportFrom(rMedium, bInsert);
384 :
385 7 : SfxItemSet* pSet = rMedium.GetItemSet();
386 7 : if( pSet )
387 : {
388 7 : if( SFX_ITEM_SET == pSet->GetItemState(SID_DOC_STARTPRESENTATION)&&
389 0 : ( (SfxBoolItem&) ( pSet->Get( SID_DOC_STARTPRESENTATION ) ) ).GetValue() )
390 : {
391 0 : mpDoc->SetStartWithPresentation( true );
392 :
393 : // tell SFX to change viewshell when in preview mode
394 0 : if( IsPreview() )
395 : {
396 0 : SfxItemSet *pMediumSet = GetMedium()->GetItemSet();
397 0 : if( pMediumSet )
398 0 : pMediumSet->Put( SfxUInt16Item( SID_VIEW_ID, 1 ) );
399 : }
400 : }
401 : }
402 :
403 7 : return bRet;
404 : }
405 :
406 : /**
407 : * load from a foreign format
408 : */
409 9 : sal_Bool DrawDocShell::ConvertFrom( SfxMedium& rMedium )
410 : {
411 9 : mbNewDocument = sal_False;
412 :
413 9 : const OUString aFilterName( rMedium.GetFilter()->GetFilterName() );
414 9 : sal_Bool bRet = sal_False;
415 9 : bool bStartPresentation = false;
416 :
417 9 : SetWaitCursor( sal_True );
418 :
419 9 : SfxItemSet* pSet = rMedium.GetItemSet();
420 9 : if( pSet )
421 : {
422 9 : if( ( SFX_ITEM_SET == pSet->GetItemState(SID_PREVIEW ) ) && ( (SfxBoolItem&) ( pSet->Get( SID_PREVIEW ) ) ).GetValue() )
423 : {
424 0 : mpDoc->SetStarDrawPreviewMode( sal_True );
425 : }
426 :
427 9 : if( SFX_ITEM_SET == pSet->GetItemState(SID_DOC_STARTPRESENTATION)&&
428 0 : ( (SfxBoolItem&) ( pSet->Get( SID_DOC_STARTPRESENTATION ) ) ).GetValue() )
429 : {
430 0 : bStartPresentation = true;
431 0 : mpDoc->SetStartWithPresentation( true );
432 : }
433 : }
434 :
435 18 : if( aFilterName == pFilterPowerPoint97
436 1 : || aFilterName == pFilterPowerPoint97Template
437 10 : || aFilterName == pFilterPowerPoint97AutoPlay)
438 : {
439 8 : mpDoc->StopWorkStartupDelay();
440 8 : bRet = SdPPTFilter( rMedium, *this, sal_True ).Import();
441 : }
442 2 : else if (aFilterName.indexOf("impress8") >= 0 ||
443 1 : aFilterName.indexOf("draw8") >= 0)
444 : {
445 : // TODO/LATER: nobody is interested in the error code?!
446 1 : mpDoc->CreateFirstPages();
447 1 : mpDoc->StopWorkStartupDelay();
448 1 : ErrCode nError = ERRCODE_NONE;
449 1 : bRet = SdXMLFilter( rMedium, *this, sal_True ).Import( nError );
450 :
451 : }
452 0 : else if (aFilterName.indexOf("StarOffice XML (Draw)") >= 0 ||
453 0 : aFilterName.indexOf("StarOffice XML (Impress)") >= 0)
454 : {
455 : // TODO/LATER: nobody is interested in the error code?!
456 0 : mpDoc->CreateFirstPages();
457 0 : mpDoc->StopWorkStartupDelay();
458 0 : ErrCode nError = ERRCODE_NONE;
459 0 : bRet = SdXMLFilter( rMedium, *this, sal_True, SDXMLMODE_Normal, SOFFICE_FILEFORMAT_60 ).Import( nError );
460 : }
461 0 : else if( aFilterName.equals( "CGM - Computer Graphics Metafile" ) )
462 : {
463 0 : mpDoc->CreateFirstPages();
464 0 : mpDoc->StopWorkStartupDelay();
465 0 : bRet = SdCGMFilter( rMedium, *this, sal_True ).Import();
466 : }
467 : else
468 : {
469 0 : mpDoc->CreateFirstPages();
470 0 : mpDoc->StopWorkStartupDelay();
471 0 : bRet = SdGRFFilter( rMedium, *this ).Import();
472 : }
473 :
474 9 : FinishedLoading( SFX_LOADED_MAINDOCUMENT | SFX_LOADED_IMAGES );
475 :
476 : // tell SFX to change viewshell when in preview mode
477 9 : if( IsPreview() )
478 : {
479 0 : SfxItemSet *pMediumSet = GetMedium()->GetItemSet();
480 :
481 0 : if( pMediumSet )
482 0 : pMediumSet->Put( SfxUInt16Item( SID_VIEW_ID, 5 ) );
483 : }
484 9 : SetWaitCursor( sal_False );
485 :
486 : // tell SFX to change viewshell when in preview mode
487 9 : if( IsPreview() || bStartPresentation )
488 : {
489 0 : SfxItemSet *pMediumSet = GetMedium()->GetItemSet();
490 0 : if( pMediumSet )
491 0 : pMediumSet->Put( SfxUInt16Item( SID_VIEW_ID, bStartPresentation ? 1 : 5 ) );
492 : }
493 :
494 9 : return bRet;
495 : }
496 :
497 : /**
498 : * Writes pools and document to the open streams
499 : */
500 0 : sal_Bool DrawDocShell::Save()
501 : {
502 0 : mpDoc->StopWorkStartupDelay();
503 :
504 : //TODO/LATER: why this?!
505 0 : if( GetCreateMode() == SFX_CREATE_MODE_STANDARD )
506 0 : SfxObjectShell::SetVisArea( Rectangle() );
507 :
508 0 : sal_Bool bRet = SfxObjectShell::Save();
509 :
510 0 : if( bRet )
511 : {
512 : // Call UpdateDocInfoForSave() before export
513 0 : UpdateDocInfoForSave();
514 :
515 0 : bRet = SdXMLFilter( *GetMedium(), *this, sal_True, SDXMLMODE_Normal, SotStorage::GetVersion( GetMedium()->GetStorage() ) ).Export();
516 : }
517 :
518 0 : return bRet;
519 : }
520 :
521 : /**
522 : * Writes pools and document to the provided storage
523 : */
524 4 : sal_Bool DrawDocShell::SaveAs( SfxMedium& rMedium )
525 : {
526 4 : mpDoc->StopWorkStartupDelay();
527 :
528 : //TODO/LATER: why this?!
529 4 : if( GetCreateMode() == SFX_CREATE_MODE_STANDARD )
530 4 : SfxObjectShell::SetVisArea( Rectangle() );
531 :
532 4 : sal_uInt32 nVBWarning = ERRCODE_NONE;
533 4 : sal_Bool bRet = SfxObjectShell::SaveAs( rMedium );
534 :
535 4 : if( bRet )
536 : {
537 : // Call UpdateDocInfoForSave() before export
538 4 : UpdateDocInfoForSave();
539 4 : bRet = SdXMLFilter( rMedium, *this, sal_True, SDXMLMODE_Normal, SotStorage::GetVersion( rMedium.GetStorage() ) ).Export();
540 : }
541 :
542 4 : if( GetError() == ERRCODE_NONE )
543 4 : SetError( nVBWarning, OSL_LOG_PREFIX );
544 :
545 4 : return bRet;
546 : }
547 :
548 : /**
549 : * save to foreign format
550 : */
551 0 : sal_Bool DrawDocShell::ConvertTo( SfxMedium& rMedium )
552 : {
553 0 : sal_Bool bRet = sal_False;
554 :
555 0 : if( mpDoc->GetPageCount() )
556 : {
557 0 : const SfxFilter* pMediumFilter = rMedium.GetFilter();
558 0 : const OUString aTypeName( pMediumFilter->GetTypeName() );
559 0 : SdFilter* pFilter = NULL;
560 :
561 0 : if( aTypeName.indexOf( "graphic_HTML" ) >= 0 )
562 : {
563 0 : pFilter = new SdHTMLFilter( rMedium, *this, sal_True );
564 : }
565 0 : else if( aTypeName.indexOf( "MS_PowerPoint_97" ) >= 0 )
566 : {
567 0 : pFilter = new SdPPTFilter( rMedium, *this, sal_True );
568 0 : ((SdPPTFilter*)pFilter)->PreSaveBasic();
569 : }
570 0 : else if ( aTypeName.indexOf( "CGM_Computer_Graphics_Metafile" ) >= 0 )
571 : {
572 0 : pFilter = new SdCGMFilter( rMedium, *this, sal_True );
573 : }
574 0 : else if( aTypeName.indexOf( "draw8" ) >= 0 ||
575 0 : aTypeName.indexOf( "impress8" ) >= 0 )
576 : {
577 0 : pFilter = new SdXMLFilter( rMedium, *this, sal_True );
578 0 : UpdateDocInfoForSave();
579 : }
580 0 : else if( aTypeName.indexOf( "StarOffice_XML_Impress" ) >= 0 ||
581 0 : aTypeName.indexOf( "StarOffice_XML_Draw" ) >= 0 )
582 : {
583 0 : pFilter = new SdXMLFilter( rMedium, *this, sal_True, SDXMLMODE_Normal, SOFFICE_FILEFORMAT_60 );
584 0 : UpdateDocInfoForSave();
585 : }
586 : else
587 : {
588 0 : pFilter = new SdGRFFilter( rMedium, *this );
589 : }
590 :
591 0 : if( pFilter )
592 : {
593 0 : const sal_uLong nOldSwapMode = mpDoc->GetSwapGraphicsMode();
594 :
595 0 : mpDoc->SetSwapGraphicsMode( SDR_SWAPGRAPHICSMODE_TEMP );
596 :
597 0 : bRet = pFilter->Export();
598 0 : if( !bRet )
599 0 : mpDoc->SetSwapGraphicsMode( nOldSwapMode );
600 :
601 0 : delete pFilter;
602 0 : }
603 : }
604 :
605 0 : return bRet;
606 : }
607 :
608 : /**
609 : * Reopen own streams to ensure that nobody else can prevent use from opening
610 : * them.
611 : */
612 4 : sal_Bool DrawDocShell::SaveCompleted( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage )
613 : {
614 4 : sal_Bool bRet = sal_False;
615 :
616 4 : if( SfxObjectShell::SaveCompleted(xStorage) )
617 : {
618 4 : mpDoc->NbcSetChanged( sal_False );
619 :
620 4 : if( mpViewShell )
621 : {
622 4 : if( mpViewShell->ISA( OutlineViewShell ) )
623 0 : static_cast<OutlineView*>(mpViewShell->GetView())
624 0 : ->GetOutliner()->ClearModifyFlag();
625 :
626 4 : SdrOutliner* pOutl = mpViewShell->GetView()->GetTextEditOutliner();
627 4 : if( pOutl )
628 : {
629 0 : SdrObject* pObj = mpViewShell->GetView()->GetTextEditObject();
630 0 : if( pObj )
631 0 : pObj->NbcSetOutlinerParaObject( pOutl->CreateParaObject() );
632 :
633 0 : pOutl->ClearModifyFlag();
634 : }
635 : }
636 :
637 4 : bRet = sal_True;
638 :
639 4 : SfxViewFrame* pFrame = ( mpViewShell && mpViewShell->GetViewFrame() ) ?
640 4 : mpViewShell->GetViewFrame() :
641 8 : SfxViewFrame::Current();
642 :
643 4 : if( pFrame )
644 4 : pFrame->GetBindings().Invalidate( SID_NAVIGATOR_STATE, sal_True, sal_False );
645 : }
646 4 : return bRet;
647 : }
648 :
649 2292 : SdDrawDocument* DrawDocShell::GetDoc()
650 : {
651 2292 : return mpDoc;
652 : }
653 :
654 5 : SfxStyleSheetBasePool* DrawDocShell::GetStyleSheetPool()
655 : {
656 5 : return( (SfxStyleSheetBasePool*) mpDoc->GetStyleSheetPool() );
657 : }
658 :
659 0 : sal_Bool DrawDocShell::GotoBookmark(const String& rBookmark)
660 : {
661 0 : sal_Bool bFound = sal_False;
662 :
663 0 : if (mpViewShell && mpViewShell->ISA(DrawViewShell))
664 : {
665 0 : DrawViewShell* pDrawViewShell = static_cast<DrawViewShell*>(mpViewShell);
666 0 : ViewShellBase& rBase (mpViewShell->GetViewShellBase());
667 :
668 0 : sal_Bool bIsMasterPage = sal_False;
669 0 : sal_uInt16 nPageNumber = SDRPAGE_NOTFOUND;
670 0 : SdrObject* pObj = NULL;
671 :
672 0 : OUString sBookmark( rBookmark );
673 0 : const OUString sInteraction( "action?" );
674 0 : if ( sBookmark.match( sInteraction ) )
675 : {
676 0 : const OUString sJump( "jump=" );
677 0 : if ( sBookmark.match( sJump, sInteraction.getLength() ) )
678 : {
679 0 : OUString aDestination( sBookmark.copy( sInteraction.getLength() + sJump.getLength() ) );
680 0 : if ( aDestination.match( "firstslide" ) )
681 : {
682 0 : nPageNumber = 1;
683 : }
684 0 : else if ( aDestination.match( "lastslide" ) )
685 : {
686 0 : nPageNumber = mpDoc->GetPageCount() - 2;
687 : }
688 0 : else if ( aDestination.match( "previousslide" ) )
689 : {
690 0 : SdPage* pPage = pDrawViewShell->GetActualPage();
691 0 : nPageNumber = pPage->GetPageNum();
692 0 : nPageNumber = nPageNumber > 2 ? nPageNumber - 2 : SDRPAGE_NOTFOUND;
693 : }
694 0 : else if ( aDestination.match( "nextslide" ) )
695 : {
696 0 : SdPage* pPage = pDrawViewShell->GetActualPage();
697 0 : nPageNumber = pPage->GetPageNum() + 2;
698 0 : if ( nPageNumber >= mpDoc->GetPageCount() )
699 0 : nPageNumber = SDRPAGE_NOTFOUND;
700 0 : }
701 0 : }
702 : }
703 : else
704 : {
705 0 : String aBookmark( rBookmark );
706 :
707 : // Is the bookmark a page?
708 0 : nPageNumber = mpDoc->GetPageByName( aBookmark, bIsMasterPage );
709 :
710 0 : if (nPageNumber == SDRPAGE_NOTFOUND)
711 : {
712 : // Is the bookmark a object?
713 0 : pObj = mpDoc->GetObj(aBookmark);
714 :
715 0 : if (pObj)
716 : {
717 0 : nPageNumber = pObj->GetPage()->GetPageNum();
718 : }
719 0 : }
720 : }
721 0 : if (nPageNumber != SDRPAGE_NOTFOUND)
722 : {
723 : // Jump to the bookmarked page. This is done in three steps.
724 :
725 0 : bFound = sal_True;
726 : SdPage* pPage;
727 0 : if (bIsMasterPage)
728 0 : pPage = (SdPage*) mpDoc->GetMasterPage(nPageNumber);
729 : else
730 0 : pPage = (SdPage*) mpDoc->GetPage(nPageNumber);
731 :
732 : // 1.) Change the view shell to the edit view, the notes view,
733 : // or the handout view.
734 0 : PageKind eNewPageKind = pPage->GetPageKind();
735 :
736 0 : if( (eNewPageKind != PK_STANDARD) && (mpDoc->GetDocumentType() == DOCUMENT_TYPE_DRAW) )
737 0 : return sal_False;
738 :
739 0 : if (eNewPageKind != pDrawViewShell->GetPageKind())
740 : {
741 : // change work area
742 0 : GetFrameView()->SetPageKind(eNewPageKind);
743 0 : OUString sViewURL;
744 0 : switch (eNewPageKind)
745 : {
746 : case PK_STANDARD:
747 0 : sViewURL = FrameworkHelper::msImpressViewURL;
748 0 : break;
749 : case PK_NOTES:
750 0 : sViewURL = FrameworkHelper::msNotesViewURL;
751 0 : break;
752 : case PK_HANDOUT:
753 0 : sViewURL = FrameworkHelper::msHandoutViewURL;
754 0 : break;
755 : default:
756 0 : break;
757 : }
758 0 : if (!sViewURL.isEmpty())
759 : {
760 : ::boost::shared_ptr<FrameworkHelper> pHelper (
761 0 : FrameworkHelper::Instance(rBase));
762 : pHelper->RequestView(
763 : sViewURL,
764 0 : FrameworkHelper::msCenterPaneURL);
765 0 : pHelper->WaitForUpdate();
766 :
767 : // Get the new DrawViewShell.
768 0 : mpViewShell = pHelper->GetViewShell(FrameworkHelper::msCenterPaneURL).get();
769 0 : pDrawViewShell = dynamic_cast<sd::DrawViewShell*>(mpViewShell);
770 : }
771 : else
772 : {
773 0 : pDrawViewShell = NULL;
774 0 : }
775 : }
776 :
777 0 : if (pDrawViewShell != NULL)
778 : {
779 : // Set the edit mode to either the normal edit mode or the
780 : // master page mode.
781 0 : EditMode eNewEditMode = EM_PAGE;
782 0 : if (bIsMasterPage)
783 : {
784 0 : eNewEditMode = EM_MASTERPAGE;
785 : }
786 :
787 0 : if (eNewEditMode != pDrawViewShell->GetEditMode())
788 : {
789 : // EditMode setzen
790 0 : pDrawViewShell->ChangeEditMode(eNewEditMode, sal_False);
791 : }
792 :
793 : // Make the bookmarked page the current page. This is done
794 : // by using the API because this takes care of all the
795 : // little things to be done. Especially writing the view
796 : // data to the frame view.
797 0 : sal_uInt16 nSdPgNum = (nPageNumber - 1) / 2;
798 0 : Reference<drawing::XDrawView> xController (rBase.GetController(), UNO_QUERY);
799 0 : if (xController.is())
800 : {
801 0 : Reference<drawing::XDrawPage> xDrawPage (pPage->getUnoPage(), UNO_QUERY);
802 0 : xController->setCurrentPage (xDrawPage);
803 : }
804 : else
805 : {
806 : // As a fall back switch to the page via the core.
807 : DBG_ASSERT (xController.is(),
808 : "DrawDocShell::GotoBookmark: can't switch page via API");
809 0 : pDrawViewShell->SwitchPage(nSdPgNum);
810 : }
811 :
812 0 : if (pObj != NULL)
813 : {
814 : // show and select object
815 0 : pDrawViewShell->MakeVisible(pObj->GetLogicRect(),
816 0 : *pDrawViewShell->GetActiveWindow());
817 0 : pDrawViewShell->GetView()->UnmarkAll();
818 0 : pDrawViewShell->GetView()->MarkObj(
819 : pObj,
820 0 : pDrawViewShell->GetView()->GetSdrPageView(), sal_False);
821 0 : }
822 : }
823 : }
824 :
825 0 : SfxBindings& rBindings = (pDrawViewShell->GetViewFrame()!=NULL
826 0 : ? pDrawViewShell->GetViewFrame()
827 0 : : SfxViewFrame::Current() )->GetBindings();
828 :
829 0 : rBindings.Invalidate(SID_NAVIGATOR_STATE, sal_True, sal_False);
830 0 : rBindings.Invalidate(SID_NAVIGATOR_PAGENAME);
831 : }
832 :
833 0 : return (bFound);
834 : }
835 :
836 : /**
837 : * If it should become a document template.
838 : */
839 4 : sal_Bool DrawDocShell::SaveAsOwnFormat( SfxMedium& rMedium )
840 : {
841 :
842 4 : const SfxFilter* pFilter = rMedium.GetFilter();
843 :
844 4 : if (pFilter->IsOwnTemplateFormat())
845 : {
846 : /* now the StarDraw specialty:
847 : we assign known layout names to the layout template of the first
848 : page, we set the layout names of the affected masterpages and pages.
849 : We inform all text objects of the affected standard, note and
850 : masterpages about the name change.
851 : */
852 :
853 0 : String aLayoutName;
854 :
855 : SfxStringItem* pLayoutItem;
856 0 : if( rMedium.GetItemSet()->GetItemState(SID_TEMPLATE_NAME, sal_False, (const SfxPoolItem**) & pLayoutItem ) == SFX_ITEM_SET )
857 : {
858 0 : aLayoutName = pLayoutItem->GetValue();
859 : }
860 : else
861 : {
862 0 : INetURLObject aURL( rMedium.GetName() );
863 0 : aURL.removeExtension();
864 0 : aLayoutName = aURL.getName();
865 : }
866 :
867 0 : if( aLayoutName.Len() )
868 : {
869 0 : sal_uInt32 nCount = mpDoc->GetMasterSdPageCount(PK_STANDARD);
870 0 : for (sal_uInt32 i = 0; i < nCount; ++i)
871 : {
872 0 : OUString aOldPageLayoutName = mpDoc->GetMasterSdPage(i, PK_STANDARD)->GetLayoutName();
873 0 : OUString aNewLayoutName = aLayoutName;
874 : // Don't add suffix for the first master page
875 0 : if( i > 0 )
876 0 : aNewLayoutName += OUString::number(i);
877 :
878 0 : mpDoc->RenameLayoutTemplate(aOldPageLayoutName, aNewLayoutName);
879 0 : }
880 0 : }
881 : }
882 :
883 4 : return SfxObjectShell::SaveAsOwnFormat(rMedium);
884 : }
885 :
886 :
887 82 : void DrawDocShell::FillClass(SvGlobalName* pClassName,
888 : sal_uInt32* pFormat,
889 : OUString* ,
890 : OUString* pFullTypeName,
891 : OUString* pShortTypeName,
892 : sal_Int32 nFileFormat,
893 : sal_Bool bTemplate /* = sal_False */) const
894 : {
895 82 : if (nFileFormat == SOFFICE_FILEFORMAT_60)
896 : {
897 2 : if ( meDocType == DOCUMENT_TYPE_DRAW )
898 : {
899 1 : *pClassName = SvGlobalName(SO3_SDRAW_CLASSID_60);
900 1 : *pFormat = SOT_FORMATSTR_ID_STARDRAW_60;
901 1 : *pFullTypeName = OUString(SdResId(STR_GRAPHIC_DOCUMENT_FULLTYPE_60));
902 : }
903 : else
904 : {
905 1 : *pClassName = SvGlobalName(SO3_SIMPRESS_CLASSID_60);
906 1 : *pFormat = SOT_FORMATSTR_ID_STARIMPRESS_60;
907 1 : *pFullTypeName = OUString(SdResId(STR_IMPRESS_DOCUMENT_FULLTYPE_60));
908 : }
909 : }
910 80 : else if (nFileFormat == SOFFICE_FILEFORMAT_8)
911 : {
912 80 : if ( meDocType == DOCUMENT_TYPE_DRAW )
913 : {
914 52 : *pClassName = SvGlobalName(SO3_SDRAW_CLASSID_60);
915 52 : *pFormat = bTemplate ? SOT_FORMATSTR_ID_STARDRAW_8_TEMPLATE : SOT_FORMATSTR_ID_STARDRAW_8;
916 52 : *pFullTypeName = "Draw 8"; // HACK: method will be removed with new storage API
917 : }
918 : else
919 : {
920 28 : *pClassName = SvGlobalName(SO3_SIMPRESS_CLASSID_60);
921 28 : *pFormat = bTemplate ? SOT_FORMATSTR_ID_STARIMPRESS_8_TEMPLATE : SOT_FORMATSTR_ID_STARIMPRESS_8;
922 28 : *pFullTypeName = "Impress 8"; // HACK: method will be removed with new storage API
923 : }
924 : }
925 :
926 164 : *pShortTypeName = OUString(SdResId( (meDocType == DOCUMENT_TYPE_DRAW) ?
927 82 : STR_GRAPHIC_DOCUMENT : STR_IMPRESS_DOCUMENT ));
928 82 : }
929 :
930 0 : OutputDevice* DrawDocShell::GetDocumentRefDev (void)
931 : {
932 0 : OutputDevice* pReferenceDevice = SfxObjectShell::GetDocumentRefDev ();
933 : // Only when our parent does not have a reference device then we return
934 : // our own.
935 0 : if (pReferenceDevice == NULL && mpDoc != NULL)
936 0 : pReferenceDevice = mpDoc->GetRefDevice ();
937 0 : return pReferenceDevice;
938 : }
939 :
940 : /** executes the SID_OPENDOC slot to let the framework open a document
941 : with the given URL and this document as a referer */
942 0 : void DrawDocShell::OpenBookmark( const String& rBookmarkURL )
943 : {
944 0 : SfxStringItem aStrItem( SID_FILE_NAME, rBookmarkURL );
945 0 : SfxStringItem aReferer( SID_REFERER, GetMedium()->GetName() );
946 0 : const SfxPoolItem* ppArgs[] = { &aStrItem, &aReferer, 0 };
947 0 : ( mpViewShell ? mpViewShell->GetViewFrame() : SfxViewFrame::Current() )->GetBindings().Execute( SID_OPENHYPERLINK, ppArgs );
948 0 : }
949 :
950 0 : SfxDocumentInfoDialog* DrawDocShell::CreateDocumentInfoDialog( ::Window *pParent, const SfxItemSet &rSet )
951 : {
952 0 : SfxDocumentInfoDialog* pDlg = new SfxDocumentInfoDialog( pParent, rSet );
953 0 : DrawDocShell* pDocSh = PTR_CAST(DrawDocShell,SfxObjectShell::Current());
954 :
955 0 : if( pDocSh == this )
956 : {
957 0 : pDlg->AddFontTabPage();
958 : }
959 0 : return pDlg;
960 : }
961 :
962 33 : } // end of namespace sd
963 :
964 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|