1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include "DrawDocShell.hxx"
#include <com/sun/star/document/PrinterIndependentLayout.hpp>
#include <tools/urlobj.hxx>
#include <sfx2/progress.hxx>
#include <vcl/waitobj.hxx>
#include <svx/svxids.hrc>
#include <editeng/editeng.hxx>
#include <editeng/editstat.hxx>
#include <editeng/flstitem.hxx>
#include <editeng/eeitem.hxx>
#include <svl/aeitem.hxx>
#include <svl/flagitem.hxx>
#include <sot/storage.hxx>
#include <sfx2/dinfdlg.hxx>
#include <sfx2/docfile.hxx>
#include <sfx2/docfilt.hxx>
#include <sfx2/dispatch.hxx>
#include <svx/svdotext.hxx>
#include <svl/style.hxx>
#include <sfx2/printer.hxx>
#include <svtools/ctrltool.hxx>
#include <svtools/sfxecode.hxx>
#include <comphelper/classids.hxx>
#include <sot/formats.hxx>
#include <sfx2/request.hxx>
#include <unotools/fltrcfg.hxx>
#include <sfx2/frame.hxx>
#include <sfx2/viewfrm.hxx>
#include <unotools/saveopt.hxx>
#include <com/sun/star/drawing/XDrawPage.hpp>
#include <com/sun/star/drawing/XDrawView.hpp>
#include <comphelper/processfactory.hxx>
#include "app.hrc"
#include "glob.hrc"
#include "strings.hrc"
#include "strmname.h"
#include "FrameView.hxx"
#include "optsitem.hxx"
#include "Outliner.hxx"
#include "sdattr.hxx"
#include "drawdoc.hxx"
#include "ViewShell.hxx"
#include "sdmod.hxx"
#include "View.hxx"
#include "sdpage.hxx"
#include "sdresid.hxx"
#include "DrawViewShell.hxx"
#include "ViewShellBase.hxx"
#include "Window.hxx"
#include "OutlineViewShell.hxx"
#include "sdxmlwrp.hxx"
#include "sdpptwrp.hxx"
#include "sdcgmfilter.hxx"
#include "sdgrffilter.hxx"
#include "sdhtmlfilter.hxx"
#include "framework/FrameworkHelper.hxx"
#include "SdUnoDrawView.hxx"
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using ::sd::framework::FrameworkHelper;
namespace sd {
/**
* Creates (if necessary) and returns a SfxPrinter
*/
SfxPrinter* DrawDocShell::GetPrinter(bool bCreate)
{
if (bCreate && !mpPrinter)
{
// create ItemSet with special pool area
SfxItemSet* pSet = new SfxItemSet( GetPool(),
SID_PRINTER_NOTFOUND_WARN, SID_PRINTER_NOTFOUND_WARN,
SID_PRINTER_CHANGESTODOC, SID_PRINTER_CHANGESTODOC,
ATTR_OPTIONS_PRINT, ATTR_OPTIONS_PRINT,
0 );
// set PrintOptionsSet
SdOptionsPrintItem aPrintItem( ATTR_OPTIONS_PRINT,
SD_MOD()->GetSdOptions(mpDoc->GetDocumentType()));
SfxFlagItem aFlagItem( SID_PRINTER_CHANGESTODOC );
sal_uInt16 nFlags = 0;
nFlags = (aPrintItem.GetOptionsPrint().IsWarningSize() ? SFX_PRINTER_CHG_SIZE : 0) |
(aPrintItem.GetOptionsPrint().IsWarningOrientation() ? SFX_PRINTER_CHG_ORIENTATION : 0);
aFlagItem.SetValue( nFlags );
pSet->Put( aPrintItem );
pSet->Put( SfxBoolItem( SID_PRINTER_NOTFOUND_WARN, aPrintItem.GetOptionsPrint().IsWarningPrinter() ) );
pSet->Put( aFlagItem );
mpPrinter = new SfxPrinter(pSet);
mbOwnPrinter = true;
// set output quality
sal_uInt16 nQuality = aPrintItem.GetOptionsPrint().GetOutputQuality();
sal_uLong nMode = DRAWMODE_DEFAULT;
// 1 == Grayscale, 2 == Black & White (with grayscale images)
if( nQuality == 1 )
nMode = DRAWMODE_GRAYLINE | DRAWMODE_GRAYFILL | DRAWMODE_GRAYTEXT | DRAWMODE_GRAYBITMAP | DRAWMODE_GRAYGRADIENT;
else if( nQuality == 2 )
nMode = DRAWMODE_BLACKLINE | DRAWMODE_WHITEFILL | DRAWMODE_BLACKTEXT | DRAWMODE_GRAYBITMAP | DRAWMODE_WHITEGRADIENT;
mpPrinter->SetDrawMode( nMode );
MapMode aMM (mpPrinter->GetMapMode());
aMM.SetMapUnit(MAP_100TH_MM);
mpPrinter->SetMapMode(aMM);
UpdateRefDevice();
}
return mpPrinter;
}
/**
* Set new SfxPrinter (transfer of ownership)
*/
void DrawDocShell::SetPrinter(SfxPrinter *pNewPrinter)
{
if ( mpViewShell )
{
::sd::View* pView = mpViewShell->GetView();
if ( pView->IsTextEdit() )
pView->SdrEndTextEdit();
}
if ( mpPrinter && mbOwnPrinter && (mpPrinter != pNewPrinter) )
{
delete mpPrinter;
}
mpPrinter = pNewPrinter;
mbOwnPrinter = true;
if ( mpDoc->GetPrinterIndependentLayout() == ::com::sun::star::document::PrinterIndependentLayout::DISABLED )
UpdateFontList();
UpdateRefDevice();
}
void DrawDocShell::UpdateFontList()
{
delete mpFontList;
OutputDevice* pRefDevice = NULL;
if ( mpDoc->GetPrinterIndependentLayout() == ::com::sun::star::document::PrinterIndependentLayout::DISABLED )
pRefDevice = GetPrinter(true);
else
pRefDevice = SD_MOD()->GetVirtualRefDevice();
mpFontList = new FontList( pRefDevice, NULL, false );
SvxFontListItem aFontListItem( mpFontList, SID_ATTR_CHAR_FONTLIST );
PutItem( aFontListItem );
}
Printer* DrawDocShell::GetDocumentPrinter()
{
return GetPrinter(false);
}
void DrawDocShell::OnDocumentPrinterChanged(Printer* pNewPrinter)
{
// if we already have a printer, see if its the same
if( mpPrinter )
{
// easy case
if( mpPrinter == pNewPrinter )
return;
// compare if its the same printer with the same job setup
if( (mpPrinter->GetName() == pNewPrinter->GetName()) &&
(mpPrinter->GetJobSetup() == pNewPrinter->GetJobSetup()))
return;
}
// if (mpPrinter->IsA(SfxPrinter))
{
// Since we do not have RTTI we use a hard cast (...)
SetPrinter((SfxPrinter*) pNewPrinter);
// container owns printer
mbOwnPrinter = false;
}
}
void DrawDocShell::UpdateRefDevice()
{
if( mpDoc )
{
// Determine the device for which the output will be formatted.
OutputDevice* pRefDevice = NULL;
switch (mpDoc->GetPrinterIndependentLayout())
{
case ::com::sun::star::document::PrinterIndependentLayout::DISABLED:
pRefDevice = mpPrinter;
break;
case ::com::sun::star::document::PrinterIndependentLayout::ENABLED:
pRefDevice = SD_MOD()->GetVirtualRefDevice();
break;
default:
// We are confronted with an invalid or un-implemented
// layout mode. Use the printer as formatting device
// as a fall-back.
DBG_ASSERT(false, "DrawDocShell::UpdateRefDevice(): Unexpected printer layout mode");
pRefDevice = mpPrinter;
break;
}
mpDoc->SetRefDevice( pRefDevice );
::sd::Outliner* pOutl = mpDoc->GetOutliner( false );
if( pOutl )
pOutl->SetRefDevice( pRefDevice );
::sd::Outliner* pInternalOutl = mpDoc->GetInternalOutliner( false );
if( pInternalOutl )
pInternalOutl->SetRefDevice( pRefDevice );
}
}
/**
* Creates new document, opens streams
*/
bool DrawDocShell::InitNew( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage )
{
bool bRet = SfxObjectShell::InitNew( xStorage );
Rectangle aVisArea( Point(0, 0), Size(14100, 10000) );
SetVisArea(aVisArea);
if (bRet)
{
if( !mbSdDataObj )
mpDoc->NewOrLoadCompleted(NEW_DOC); // otherwise calling
// NewOrLoadCompleted(NEW_LOADED) in
// SdDrawDocument::AllocModel()
}
return bRet;
}
/**
* loads pools and document
*/
bool DrawDocShell::Load( SfxMedium& rMedium )
{
mbNewDocument = false;
bool bRet = false;
bool bStartPresentation = false;
ErrCode nError = ERRCODE_NONE;
SfxItemSet* pSet = rMedium.GetItemSet();
if( pSet )
{
if( ( SFX_ITEM_SET == pSet->GetItemState(SID_PREVIEW ) ) && ( (SfxBoolItem&) ( pSet->Get( SID_PREVIEW ) ) ).GetValue() )
{
mpDoc->SetStarDrawPreviewMode( true );
}
if( SFX_ITEM_SET == pSet->GetItemState(SID_DOC_STARTPRESENTATION)&&
( (SfxBoolItem&) ( pSet->Get( SID_DOC_STARTPRESENTATION ) ) ).GetValue() )
{
bStartPresentation = true;
mpDoc->SetStartWithPresentation( true );
}
}
bRet = SfxObjectShell::Load( rMedium );
if(bRet)
{
comphelper::EmbeddedObjectContainer& rEmbeddedObjectContainer = getEmbeddedObjectContainer();
rEmbeddedObjectContainer.setUserAllowsLinkUpdate(false);
bRet = SdXMLFilter( rMedium, *this, true, SDXMLMODE_Normal, SotStorage::GetVersion( rMedium.GetStorage() ) ).Import( nError );
}
if( bRet )
{
UpdateTablePointers();
// If we're an embedded OLE object, use tight bounds
// for our visArea. No point in showing the user lots of empty
// space. Had to remove the check for empty VisArea below,
// since XML load always sets a VisArea before.
//TODO/LATER: looks a little bit strange!
if( ( GetCreateMode() == SFX_CREATE_MODE_EMBEDDED ) && SfxObjectShell::GetVisArea( ASPECT_CONTENT ).IsEmpty() )
{
SdPage* pPage = mpDoc->GetSdPage( 0, PK_STANDARD );
if( pPage )
SetVisArea( Rectangle( pPage->GetAllObjBoundRect() ) );
}
FinishedLoading( SFX_LOADED_ALL );
const INetURLObject aUrl;
SfxObjectShell::SetAutoLoad( aUrl, 0, false );
}
else
{
if( nError == ERRCODE_IO_BROKENPACKAGE )
SetError( ERRCODE_IO_BROKENPACKAGE, OSL_LOG_PREFIX );
// TODO/LATER: correct error handling?!
//pStore->SetError( SVSTREAM_WRONGVERSION, OUString( OSL_LOG_PREFIX ) );
else
SetError( ERRCODE_ABORT, OSL_LOG_PREFIX );
}
// tell SFX to change viewshell when in preview mode
if( IsPreview() || bStartPresentation )
{
SfxItemSet *pMediumSet = GetMedium()->GetItemSet();
if( pMediumSet )
pMediumSet->Put( SfxUInt16Item( SID_VIEW_ID, bStartPresentation ? 1 : 5 ) );
}
return bRet;
}
/**
* loads content for organizer
*/
bool DrawDocShell::LoadFrom( SfxMedium& rMedium )
{
mbNewDocument = false;
WaitObject* pWait = NULL;
if( mpViewShell )
pWait = new WaitObject( (Window*) mpViewShell->GetActiveWindow() );
mpDoc->NewOrLoadCompleted( NEW_DOC );
mpDoc->CreateFirstPages();
mpDoc->StopWorkStartupDelay();
// TODO/LATER: nobody is interested in the error code?!
ErrCode nError = ERRCODE_NONE;
bool bRet = SdXMLFilter( rMedium, *this, true, SDXMLMODE_Organizer, SotStorage::GetVersion( rMedium.GetStorage() ) ).Import( nError );
// tell SFX to change viewshell when in preview mode
if( IsPreview() )
{
SfxItemSet *pSet = GetMedium()->GetItemSet();
if( pSet )
pSet->Put( SfxUInt16Item( SID_VIEW_ID, 5 ) );
}
delete pWait;
return bRet;
}
/**
* load from 3rd party format
*/
bool DrawDocShell::ImportFrom(SfxMedium &rMedium,
uno::Reference<text::XTextRange> const& xInsertPosition)
{
const OUString aFilterName( rMedium.GetFilter()->GetFilterName() );
if( aFilterName == "Impress MS PowerPoint 2007 XML" ||
aFilterName == "Impress MS PowerPoint 2007 XML AutoPlay" )
{
// As this is a MSFT format, we should use the "MS Compat"
// mode for spacing before and after paragraphs.
// This is copied from what is done for .ppt import in
// ImplSdPPTImport::Import() in sd/source/filter/ppt/pptin.cxx
// in. We need to tell both the edit engine of the draw outliner,
// and the document, to do "summation of paragraphs".
SdrOutliner& rOutl = mpDoc->GetDrawOutliner();
sal_uInt32 nControlWord = rOutl.GetEditEngine().GetControlWord();
nControlWord |= EE_CNTRL_ULSPACESUMMATION;
nControlWord &=~ EE_CNTRL_ULSPACEFIRSTPARA;
((EditEngine&)rOutl.GetEditEngine()).SetControlWord( nControlWord );
mpDoc->SetSummationOfParagraphs( true );
}
const bool bRet = SfxObjectShell::ImportFrom(rMedium, xInsertPosition);
SfxItemSet* pSet = rMedium.GetItemSet();
if( pSet )
{
if( SFX_ITEM_SET == pSet->GetItemState(SID_DOC_STARTPRESENTATION)&&
( (SfxBoolItem&) ( pSet->Get( SID_DOC_STARTPRESENTATION ) ) ).GetValue() )
{
mpDoc->SetStartWithPresentation( true );
// tell SFX to change viewshell when in preview mode
if( IsPreview() )
{
SfxItemSet *pMediumSet = GetMedium()->GetItemSet();
if( pMediumSet )
pMediumSet->Put( SfxUInt16Item( SID_VIEW_ID, 1 ) );
}
}
}
return bRet;
}
/**
* load from a foreign format
*/
bool DrawDocShell::ConvertFrom( SfxMedium& rMedium )
{
mbNewDocument = false;
const OUString aFilterName( rMedium.GetFilter()->GetFilterName() );
bool bRet = false;
bool bStartPresentation = false;
SetWaitCursor( true );
SfxItemSet* pSet = rMedium.GetItemSet();
if( pSet )
{
if( ( SFX_ITEM_SET == pSet->GetItemState(SID_PREVIEW ) ) && ( (SfxBoolItem&) ( pSet->Get( SID_PREVIEW ) ) ).GetValue() )
{
mpDoc->SetStarDrawPreviewMode( true );
}
if( SFX_ITEM_SET == pSet->GetItemState(SID_DOC_STARTPRESENTATION)&&
( (SfxBoolItem&) ( pSet->Get( SID_DOC_STARTPRESENTATION ) ) ).GetValue() )
{
bStartPresentation = true;
mpDoc->SetStartWithPresentation( true );
}
}
if( aFilterName == pFilterPowerPoint97
|| aFilterName == pFilterPowerPoint97Template
|| aFilterName == pFilterPowerPoint97AutoPlay)
{
mpDoc->StopWorkStartupDelay();
bRet = SdPPTFilter( rMedium, *this, true ).Import();
}
else if (aFilterName.indexOf("impress8") >= 0 ||
aFilterName.indexOf("draw8") >= 0)
{
// TODO/LATER: nobody is interested in the error code?!
mpDoc->CreateFirstPages();
mpDoc->StopWorkStartupDelay();
ErrCode nError = ERRCODE_NONE;
bRet = SdXMLFilter( rMedium, *this, true ).Import( nError );
}
else if (aFilterName.indexOf("StarOffice XML (Draw)") >= 0 ||
aFilterName.indexOf("StarOffice XML (Impress)") >= 0)
{
// TODO/LATER: nobody is interested in the error code?!
mpDoc->CreateFirstPages();
mpDoc->StopWorkStartupDelay();
ErrCode nError = ERRCODE_NONE;
bRet = SdXMLFilter( rMedium, *this, true, SDXMLMODE_Normal, SOFFICE_FILEFORMAT_60 ).Import( nError );
}
else if( aFilterName.equals( "CGM - Computer Graphics Metafile" ) )
{
mpDoc->CreateFirstPages();
mpDoc->StopWorkStartupDelay();
bRet = SdCGMFilter( rMedium, *this, true ).Import();
}
else
{
mpDoc->CreateFirstPages();
mpDoc->StopWorkStartupDelay();
bRet = SdGRFFilter( rMedium, *this ).Import();
}
FinishedLoading( SFX_LOADED_MAINDOCUMENT | SFX_LOADED_IMAGES );
// tell SFX to change viewshell when in preview mode
if( IsPreview() )
{
SfxItemSet *pMediumSet = GetMedium()->GetItemSet();
if( pMediumSet )
pMediumSet->Put( SfxUInt16Item( SID_VIEW_ID, 5 ) );
}
SetWaitCursor( false );
// tell SFX to change viewshell when in preview mode
if( IsPreview() || bStartPresentation )
{
SfxItemSet *pMediumSet = GetMedium()->GetItemSet();
if( pMediumSet )
pMediumSet->Put( SfxUInt16Item( SID_VIEW_ID, bStartPresentation ? 1 : 5 ) );
}
return bRet;
}
/**
* Writes pools and document to the open streams
*/
bool DrawDocShell::Save()
{
mpDoc->StopWorkStartupDelay();
//TODO/LATER: why this?!
if( GetCreateMode() == SFX_CREATE_MODE_STANDARD )
SfxObjectShell::SetVisArea( Rectangle() );
bool bRet = SfxObjectShell::Save();
if( bRet )
bRet = SdXMLFilter( *GetMedium(), *this, true, SDXMLMODE_Normal, SotStorage::GetVersion( GetMedium()->GetStorage() ) ).Export();
return bRet;
}
/**
* Writes pools and document to the provided storage
*/
bool DrawDocShell::SaveAs( SfxMedium& rMedium )
{
mpDoc->setDocAccTitle(OUString());
SfxViewFrame* pFrame1 = SfxViewFrame::GetFirst( this );
if (pFrame1)
{
::Window* pWindow = &pFrame1->GetWindow();
if ( pWindow )
{
::Window* pSysWin = pWindow->GetSystemWindow();
if ( pSysWin )
{
pSysWin->SetAccessibleName(OUString());
}
}
}
mpDoc->StopWorkStartupDelay();
//TODO/LATER: why this?!
if( GetCreateMode() == SFX_CREATE_MODE_STANDARD )
SfxObjectShell::SetVisArea( Rectangle() );
sal_uInt32 nVBWarning = ERRCODE_NONE;
bool bRet = SfxObjectShell::SaveAs( rMedium );
if( bRet )
bRet = SdXMLFilter( rMedium, *this, true, SDXMLMODE_Normal, SotStorage::GetVersion( rMedium.GetStorage() ) ).Export();
if( GetError() == ERRCODE_NONE )
SetError( nVBWarning, OSL_LOG_PREFIX );
return bRet;
}
/**
* save to foreign format
*/
bool DrawDocShell::ConvertTo( SfxMedium& rMedium )
{
bool bRet = false;
if( mpDoc->GetPageCount() )
{
const SfxFilter* pMediumFilter = rMedium.GetFilter();
const OUString aTypeName( pMediumFilter->GetTypeName() );
SdFilter* pFilter = NULL;
if( aTypeName.indexOf( "graphic_HTML" ) >= 0 )
{
pFilter = new SdHTMLFilter( rMedium, *this, true );
}
else if( aTypeName.indexOf( "MS_PowerPoint_97" ) >= 0 )
{
pFilter = new SdPPTFilter( rMedium, *this, true );
((SdPPTFilter*)pFilter)->PreSaveBasic();
}
else if ( aTypeName.indexOf( "CGM_Computer_Graphics_Metafile" ) >= 0 )
{
pFilter = new SdCGMFilter( rMedium, *this, true );
}
else if( aTypeName.indexOf( "draw8" ) >= 0 ||
aTypeName.indexOf( "impress8" ) >= 0 )
{
pFilter = new SdXMLFilter( rMedium, *this, true );
}
else if( aTypeName.indexOf( "StarOffice_XML_Impress" ) >= 0 ||
aTypeName.indexOf( "StarOffice_XML_Draw" ) >= 0 )
{
pFilter = new SdXMLFilter( rMedium, *this, true, SDXMLMODE_Normal, SOFFICE_FILEFORMAT_60 );
}
else
{
pFilter = new SdGRFFilter( rMedium, *this );
}
if( pFilter )
{
const sal_uLong nOldSwapMode = mpDoc->GetSwapGraphicsMode();
mpDoc->SetSwapGraphicsMode( SDR_SWAPGRAPHICSMODE_TEMP );
bRet = pFilter->Export();
if( !bRet )
mpDoc->SetSwapGraphicsMode( nOldSwapMode );
delete pFilter;
}
}
return bRet;
}
/**
* Reopen own streams to ensure that nobody else can prevent use from opening
* them.
*/
bool DrawDocShell::SaveCompleted( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage )
{
bool bRet = false;
if( SfxObjectShell::SaveCompleted(xStorage) )
{
mpDoc->NbcSetChanged( false );
if( mpViewShell )
{
if( mpViewShell->ISA( OutlineViewShell ) )
static_cast<OutlineView*>(mpViewShell->GetView())
->GetOutliner()->ClearModifyFlag();
SdrOutliner* pOutl = mpViewShell->GetView()->GetTextEditOutliner();
if( pOutl )
{
SdrObject* pObj = mpViewShell->GetView()->GetTextEditObject();
if( pObj )
pObj->NbcSetOutlinerParaObject( pOutl->CreateParaObject() );
pOutl->ClearModifyFlag();
}
}
bRet = true;
SfxViewFrame* pFrame = ( mpViewShell && mpViewShell->GetViewFrame() ) ?
mpViewShell->GetViewFrame() :
SfxViewFrame::Current();
if( pFrame )
pFrame->GetBindings().Invalidate( SID_NAVIGATOR_STATE, true, false );
}
return bRet;
}
SdDrawDocument* DrawDocShell::GetDoc()
{
return mpDoc;
}
SfxStyleSheetBasePool* DrawDocShell::GetStyleSheetPool()
{
return( (SfxStyleSheetBasePool*) mpDoc->GetStyleSheetPool() );
}
bool DrawDocShell::GotoBookmark(const OUString& rBookmark)
{
bool bFound = false;
if (mpViewShell && mpViewShell->ISA(DrawViewShell))
{
DrawViewShell* pDrawViewShell = static_cast<DrawViewShell*>(mpViewShell);
ViewShellBase& rBase (mpViewShell->GetViewShellBase());
bool bIsMasterPage = false;
sal_uInt16 nPageNumber = SDRPAGE_NOTFOUND;
SdrObject* pObj = NULL;
OUString sBookmark( rBookmark );
const OUString sInteraction( "action?" );
if ( sBookmark.match( sInteraction ) )
{
const OUString sJump( "jump=" );
if ( sBookmark.match( sJump, sInteraction.getLength() ) )
{
OUString aDestination( sBookmark.copy( sInteraction.getLength() + sJump.getLength() ) );
if ( aDestination.match( "firstslide" ) )
{
nPageNumber = 1;
}
else if ( aDestination.match( "lastslide" ) )
{
nPageNumber = mpDoc->GetPageCount() - 2;
}
else if ( aDestination.match( "previousslide" ) )
{
SdPage* pPage = pDrawViewShell->GetActualPage();
nPageNumber = pPage->GetPageNum();
nPageNumber = nPageNumber > 2 ? nPageNumber - 2 : SDRPAGE_NOTFOUND;
}
else if ( aDestination.match( "nextslide" ) )
{
SdPage* pPage = pDrawViewShell->GetActualPage();
nPageNumber = pPage->GetPageNum() + 2;
if ( nPageNumber >= mpDoc->GetPageCount() )
nPageNumber = SDRPAGE_NOTFOUND;
}
}
}
else
{
OUString aBookmark( rBookmark );
// Is the bookmark a page?
nPageNumber = mpDoc->GetPageByName( aBookmark, bIsMasterPage );
if (nPageNumber == SDRPAGE_NOTFOUND)
{
// Is the bookmark a object?
pObj = mpDoc->GetObj(aBookmark);
if (pObj)
{
nPageNumber = pObj->GetPage()->GetPageNum();
}
}
}
if (nPageNumber != SDRPAGE_NOTFOUND)
{
// Jump to the bookmarked page. This is done in three steps.
bFound = true;
SdPage* pPage;
if (bIsMasterPage)
pPage = (SdPage*) mpDoc->GetMasterPage(nPageNumber);
else
pPage = (SdPage*) mpDoc->GetPage(nPageNumber);
// 1.) Change the view shell to the edit view, the notes view,
// or the handout view.
PageKind eNewPageKind = pPage->GetPageKind();
if( (eNewPageKind != PK_STANDARD) && (mpDoc->GetDocumentType() == DOCUMENT_TYPE_DRAW) )
return false;
if (eNewPageKind != pDrawViewShell->GetPageKind())
{
// change work area
GetFrameView()->SetPageKind(eNewPageKind);
OUString sViewURL;
switch (eNewPageKind)
{
case PK_STANDARD:
sViewURL = FrameworkHelper::msImpressViewURL;
break;
case PK_NOTES:
sViewURL = FrameworkHelper::msNotesViewURL;
break;
case PK_HANDOUT:
sViewURL = FrameworkHelper::msHandoutViewURL;
break;
default:
break;
}
if (!sViewURL.isEmpty())
{
::boost::shared_ptr<FrameworkHelper> pHelper (
FrameworkHelper::Instance(rBase));
pHelper->RequestView(
sViewURL,
FrameworkHelper::msCenterPaneURL);
pHelper->WaitForUpdate();
// Get the new DrawViewShell.
mpViewShell = pHelper->GetViewShell(FrameworkHelper::msCenterPaneURL).get();
pDrawViewShell = dynamic_cast<sd::DrawViewShell*>(mpViewShell);
}
else
{
pDrawViewShell = NULL;
}
}
if (pDrawViewShell != NULL)
{
// Set the edit mode to either the normal edit mode or the
// master page mode.
EditMode eNewEditMode = EM_PAGE;
if (bIsMasterPage)
{
eNewEditMode = EM_MASTERPAGE;
}
if (eNewEditMode != pDrawViewShell->GetEditMode())
{
// EditMode setzen
pDrawViewShell->ChangeEditMode(eNewEditMode, false);
}
// Make the bookmarked page the current page. This is done
// by using the API because this takes care of all the
// little things to be done. Especially writing the view
// data to the frame view.
sal_uInt16 nSdPgNum = (nPageNumber - 1) / 2;
Reference<drawing::XDrawView> xController (rBase.GetController(), UNO_QUERY);
if (xController.is())
{
Reference<drawing::XDrawPage> xDrawPage (pPage->getUnoPage(), UNO_QUERY);
xController->setCurrentPage (xDrawPage);
}
else
{
// As a fall back switch to the page via the core.
DBG_ASSERT (xController.is(),
"DrawDocShell::GotoBookmark: can't switch page via API");
pDrawViewShell->SwitchPage(nSdPgNum);
}
if (pObj != NULL)
{
// show and select object
pDrawViewShell->MakeVisible(pObj->GetLogicRect(),
*pDrawViewShell->GetActiveWindow());
pDrawViewShell->GetView()->UnmarkAll();
pDrawViewShell->GetView()->MarkObj(
pObj,
pDrawViewShell->GetView()->GetSdrPageView(), false);
}
}
}
SfxBindings& rBindings = (pDrawViewShell->GetViewFrame()!=NULL
? pDrawViewShell->GetViewFrame()
: SfxViewFrame::Current() )->GetBindings();
rBindings.Invalidate(SID_NAVIGATOR_STATE, true, false);
rBindings.Invalidate(SID_NAVIGATOR_PAGENAME);
}
return (bFound);
}
//If object is marked , return true , else return false .
bool DrawDocShell::IsMarked( SdrObject* pObject )
{
bool bisMarked =false;
if (mpViewShell && mpViewShell->ISA(DrawViewShell))
{
DrawViewShell* pDrViewSh = (DrawViewShell*) mpViewShell;
if (pObject )
{
bisMarked = pDrViewSh->GetView()->IsObjMarked(pObject);
}
}
return bisMarked;
}
//If object is marked , return true , else return false .
bool DrawDocShell::GetObjectIsmarked(const OUString& rBookmark)
{
OSL_TRACE("GotoBookmark %s",
OUStringToOString(rBookmark, RTL_TEXTENCODING_UTF8).getStr());
bool bUnMark = false;
if (mpViewShell && mpViewShell->ISA(DrawViewShell))
{
DrawViewShell* pDrViewSh = (DrawViewShell*) mpViewShell;
OUString aBookmark( rBookmark );
if( rBookmark.startsWith("#") )
aBookmark = rBookmark.copy( 1 );
// Ist das Bookmark eine Seite?
bool bIsMasterPage;
sal_uInt16 nPgNum = mpDoc->GetPageByName( aBookmark, bIsMasterPage );
SdrObject* pObj = NULL;
if (nPgNum == SDRPAGE_NOTFOUND)
{
// Ist das Bookmark ein Objekt?
pObj = mpDoc->GetObj(aBookmark);
if (pObj)
{
nPgNum = pObj->GetPage()->GetPageNum();
}
}
if (nPgNum != SDRPAGE_NOTFOUND)
{
/**********************************************************
* Zur Seite springen
**********************************************************/
SdPage* pPage = (SdPage*) mpDoc->GetPage(nPgNum);
PageKind eNewPageKind = pPage->GetPageKind();
if (eNewPageKind != pDrViewSh->GetPageKind())
{
// Arbeitsbereich wechseln
GetFrameView()->SetPageKind(eNewPageKind);
( ( mpViewShell && mpViewShell->GetViewFrame() ) ?
mpViewShell->GetViewFrame() : SfxViewFrame::Current() )->
GetDispatcher()->Execute( SID_VIEWSHELL0, SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD );
// Die aktuelle ViewShell hat sich geaendert!
pDrViewSh = (DrawViewShell*) mpViewShell;
}
EditMode eNewEditMode = EM_PAGE;
if( bIsMasterPage )
{
eNewEditMode = EM_MASTERPAGE;
}
if (eNewEditMode != pDrViewSh->GetEditMode())
{
// EditMode setzen
pDrViewSh->ChangeEditMode(eNewEditMode, false);
}
// Jump to the page. This is done by using the API because this
// takes care of all the little things to be done. Especially
// writing the view data to the frame view (see bug #107803#).
sal_uInt16 nSdPgNum = (nPgNum - 1) / 2;
SdUnoDrawView* pUnoDrawView = new SdUnoDrawView (
*pDrViewSh,
*pDrViewSh->GetView());
if (pUnoDrawView != NULL)
{
::com::sun::star::uno::Reference<
::com::sun::star::drawing::XDrawPage> xDrawPage (
pPage->getUnoPage(), ::com::sun::star::uno::UNO_QUERY);
pUnoDrawView->setCurrentPage (xDrawPage);
}
else
{
// As a fall back switch to the page via the core.
DBG_ASSERT (pUnoDrawView!=NULL,
"SdDrawDocShell::GotoBookmark: can't switch page via API");
pDrViewSh->SwitchPage(nSdPgNum);
}
delete pUnoDrawView;
if (pObj)
{
// Objekt einblenden und selektieren
pDrViewSh->MakeVisible(pObj->GetLogicRect(),
*pDrViewSh->GetActiveWindow());
bUnMark = pDrViewSh->GetView()->IsObjMarked(pObj);
}
}
}
return ( bUnMark);
}
//realize multi-selection of objects
bool DrawDocShell::GotoTreeBookmark(const OUString& rBookmark)
{
OSL_TRACE("GotoBookmark %s",
OUStringToOString(rBookmark, RTL_TEXTENCODING_UTF8).getStr());
bool bFound = false;
if (mpViewShell && mpViewShell->ISA(DrawViewShell))
{
DrawViewShell* pDrViewSh = (DrawViewShell*) mpViewShell;
OUString aBookmark( rBookmark );
if( rBookmark.startsWith("#") )
aBookmark = rBookmark.copy( 1 );
// Ist das Bookmark eine Seite?
bool bIsMasterPage;
sal_uInt16 nPgNum = mpDoc->GetPageByName( aBookmark, bIsMasterPage );
SdrObject* pObj = NULL;
if (nPgNum == SDRPAGE_NOTFOUND)
{
// Ist das Bookmark ein Objekt?
pObj = mpDoc->GetObj(aBookmark);
if (pObj)
{
nPgNum = pObj->GetPage()->GetPageNum();
}
}
if (nPgNum != SDRPAGE_NOTFOUND)
{
/**********************************************************
* Zur Seite springen
**********************************************************/
bFound = true;
SdPage* pPage = (SdPage*) mpDoc->GetPage(nPgNum);
PageKind eNewPageKind = pPage->GetPageKind();
if (eNewPageKind != pDrViewSh->GetPageKind())
{
// Arbeitsbereich wechseln
GetFrameView()->SetPageKind(eNewPageKind);
( ( mpViewShell && mpViewShell->GetViewFrame() ) ?
mpViewShell->GetViewFrame() : SfxViewFrame::Current() )->
GetDispatcher()->Execute( SID_VIEWSHELL0, SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD );
// Die aktuelle ViewShell hat sich geaendert!
pDrViewSh = (DrawViewShell*) mpViewShell;
}
EditMode eNewEditMode = EM_PAGE;
if( bIsMasterPage )
{
eNewEditMode = EM_MASTERPAGE;
}
if (eNewEditMode != pDrViewSh->GetEditMode())
{
// EditMode setzen
pDrViewSh->ChangeEditMode(eNewEditMode, false);
}
// Jump to the page. This is done by using the API because this
// takes care of all the little things to be done. Especially
// writing the view data to the frame view (see bug #107803#).
sal_uInt16 nSdPgNum = (nPgNum - 1) / 2;
SdUnoDrawView* pUnoDrawView = new SdUnoDrawView (
*pDrViewSh,
*pDrViewSh->GetView());
if (pUnoDrawView != NULL)
{
::com::sun::star::uno::Reference<
::com::sun::star::drawing::XDrawPage> xDrawPage (
pPage->getUnoPage(), ::com::sun::star::uno::UNO_QUERY);
pUnoDrawView->setCurrentPage (xDrawPage);
}
else
{
// As a fall back switch to the page via the core.
DBG_ASSERT (pUnoDrawView!=NULL,
"SdDrawDocShell::GotoBookmark: can't switch page via API");
pDrViewSh->SwitchPage(nSdPgNum);
}
delete pUnoDrawView;
if (pObj)
{
// Objekt einblenden und selektieren
pDrViewSh->MakeVisible(pObj->GetLogicRect(),
*pDrViewSh->GetActiveWindow());
bool bUnMark = pDrViewSh->GetView()->IsObjMarked(pObj);
pDrViewSh->GetView()->MarkObj(pObj, pDrViewSh->GetView()->GetSdrPageView(), bUnMark);
}
}
SfxBindings& rBindings = ( ( mpViewShell && mpViewShell->GetViewFrame() ) ?
mpViewShell->GetViewFrame() : SfxViewFrame::Current() )->GetBindings();
rBindings.Invalidate(SID_NAVIGATOR_STATE, true, false);
rBindings.Invalidate(SID_NAVIGATOR_PAGENAME);
}
return (bFound);
}
/**
* If it should become a document template.
*/
bool DrawDocShell::SaveAsOwnFormat( SfxMedium& rMedium )
{
const SfxFilter* pFilter = rMedium.GetFilter();
if (pFilter->IsOwnTemplateFormat())
{
/* now the StarDraw specialty:
we assign known layout names to the layout template of the first
page, we set the layout names of the affected masterpages and pages.
We inform all text objects of the affected standard, note and
masterpages about the name change.
*/
OUString aLayoutName;
SfxStringItem* pLayoutItem;
if( rMedium.GetItemSet()->GetItemState(SID_TEMPLATE_NAME, false, (const SfxPoolItem**) & pLayoutItem ) == SFX_ITEM_SET )
{
aLayoutName = pLayoutItem->GetValue();
}
else
{
INetURLObject aURL( rMedium.GetName() );
aURL.removeExtension();
aLayoutName = aURL.getName();
}
if (!aLayoutName.isEmpty())
{
sal_uInt32 nCount = mpDoc->GetMasterSdPageCount(PK_STANDARD);
for (sal_uInt32 i = 0; i < nCount; ++i)
{
OUString aOldPageLayoutName = mpDoc->GetMasterSdPage(i, PK_STANDARD)->GetLayoutName();
OUString aNewLayoutName = aLayoutName;
// Don't add suffix for the first master page
if( i > 0 )
aNewLayoutName += OUString::number(i);
mpDoc->RenameLayoutTemplate(aOldPageLayoutName, aNewLayoutName);
}
}
}
return SfxObjectShell::SaveAsOwnFormat(rMedium);
}
void DrawDocShell::FillClass(SvGlobalName* pClassName,
sal_uInt32* pFormat,
OUString* ,
OUString* pFullTypeName,
OUString* pShortTypeName,
sal_Int32 nFileFormat,
bool bTemplate /* = false */) const
{
if (nFileFormat == SOFFICE_FILEFORMAT_60)
{
if ( meDocType == DOCUMENT_TYPE_DRAW )
{
*pClassName = SvGlobalName(SO3_SDRAW_CLASSID_60);
*pFormat = SOT_FORMATSTR_ID_STARDRAW_60;
*pFullTypeName = OUString(SdResId(STR_GRAPHIC_DOCUMENT_FULLTYPE_60));
}
else
{
*pClassName = SvGlobalName(SO3_SIMPRESS_CLASSID_60);
*pFormat = SOT_FORMATSTR_ID_STARIMPRESS_60;
*pFullTypeName = OUString(SdResId(STR_IMPRESS_DOCUMENT_FULLTYPE_60));
}
}
else if (nFileFormat == SOFFICE_FILEFORMAT_8)
{
if ( meDocType == DOCUMENT_TYPE_DRAW )
{
*pClassName = SvGlobalName(SO3_SDRAW_CLASSID_60);
*pFormat = bTemplate ? SOT_FORMATSTR_ID_STARDRAW_8_TEMPLATE : SOT_FORMATSTR_ID_STARDRAW_8;
*pFullTypeName = "Draw 8"; // HACK: method will be removed with new storage API
}
else
{
*pClassName = SvGlobalName(SO3_SIMPRESS_CLASSID_60);
*pFormat = bTemplate ? SOT_FORMATSTR_ID_STARIMPRESS_8_TEMPLATE : SOT_FORMATSTR_ID_STARIMPRESS_8;
*pFullTypeName = "Impress 8"; // HACK: method will be removed with new storage API
}
}
*pShortTypeName = OUString(SdResId( (meDocType == DOCUMENT_TYPE_DRAW) ?
STR_GRAPHIC_DOCUMENT : STR_IMPRESS_DOCUMENT ));
}
OutputDevice* DrawDocShell::GetDocumentRefDev (void)
{
OutputDevice* pReferenceDevice = SfxObjectShell::GetDocumentRefDev ();
// Only when our parent does not have a reference device then we return
// our own.
if (pReferenceDevice == NULL && mpDoc != NULL)
pReferenceDevice = mpDoc->GetRefDevice ();
return pReferenceDevice;
}
/** executes the SID_OPENDOC slot to let the framework open a document
with the given URL and this document as a referer */
void DrawDocShell::OpenBookmark( const OUString& rBookmarkURL )
{
SfxStringItem aStrItem( SID_FILE_NAME, rBookmarkURL );
SfxStringItem aReferer( SID_REFERER, GetMedium()->GetName() );
const SfxPoolItem* ppArgs[] = { &aStrItem, &aReferer, 0 };
( mpViewShell ? mpViewShell->GetViewFrame() : SfxViewFrame::Current() )->GetBindings().Execute( SID_OPENHYPERLINK, ppArgs );
}
SfxDocumentInfoDialog* DrawDocShell::CreateDocumentInfoDialog( ::Window *pParent, const SfxItemSet &rSet )
{
SfxDocumentInfoDialog* pDlg = new SfxDocumentInfoDialog( pParent, rSet );
DrawDocShell* pDocSh = PTR_CAST(DrawDocShell,SfxObjectShell::Current());
if( pDocSh == this )
{
pDlg->AddFontTabPage();
}
return pDlg;
}
void DrawDocShell::setDocAccTitle( const OUString& rTitle )
{
if (mpDoc )
{
mpDoc->setDocAccTitle( rTitle );
}
}
const OUString DrawDocShell::getDocAccTitle() const
{
OUString sRet;
if (mpDoc)
{
sRet = mpDoc->getDocAccTitle();
}
return sRet;
}
void DrawDocShell::setDocReadOnly( bool bReadOnly)
{
if (mpDoc )
{
mpDoc->setDocReadOnly( bReadOnly );
}
}
bool DrawDocShell::getDocReadOnly() const
{
if (mpDoc)
{
return mpDoc->getDocReadOnly();
}
return false;
}
} // end of namespace sd
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|