LCOV - code coverage report
Current view: top level - sd/source/ui/app - sdmod2.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 91 370 24.6 %
Date: 2015-06-13 12:38:46 Functions: 5 8 62.5 %
Legend: Lines: hit not hit

          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             : #include <editeng/eeitem.hxx>
      21             : #include <editeng/flditem.hxx>
      22             : #include <sfx2/printer.hxx>
      23             : #include <svl/inethist.hxx>
      24             : #include <svl/poolitem.hxx>
      25             : #include <svl/flagitem.hxx>
      26             : #include <unotools/useroptions.hxx>
      27             : #include <sfx2/bindings.hxx>
      28             : #include <vcl/msgbox.hxx>
      29             : #include <sfx2/viewfrm.hxx>
      30             : #include <sfx2/docfile.hxx>
      31             : #include <sfx2/request.hxx>
      32             : 
      33             : #include <editeng/measfld.hxx>
      34             : #include <editeng/editstat.hxx>
      35             : #include <editeng/editeng.hxx>
      36             : 
      37             : #include <svx/dialogs.hrc>
      38             : #include <svx/svdotext.hxx>
      39             : #include <svx/svdpagv.hxx>
      40             : #include <svx/svdopage.hxx>
      41             : 
      42             : #include <sfx2/sfxdlg.hxx>
      43             : 
      44             : #include <svx/sdr/contact/displayinfo.hxx>
      45             : 
      46             : #include "sdmod.hxx"
      47             : #include "app.hrc"
      48             : #include "glob.hrc"
      49             : #include "strings.hrc"
      50             : #include "res_bmp.hrc"
      51             : #include "ViewShell.hxx"
      52             : #include "FrameView.hxx"
      53             : #include "sdattr.hxx"
      54             : #include "optsitem.hxx"
      55             : #include "DrawDocShell.hxx"
      56             : #include "drawdoc.hxx"
      57             : #include "Outliner.hxx"
      58             : #include "sdresid.hxx"
      59             : #include "pres.hxx"
      60             : #include "DrawViewShell.hxx"
      61             : #include "OutlineViewShell.hxx"
      62             : #include "OutlineView.hxx"
      63             : #include "ViewShellBase.hxx"
      64             : #include "sdpage.hxx"
      65             : #include "sdxfer.hxx"
      66             : #include "sdabstdlg.hxx"
      67             : #include <svl/intitem.hxx>
      68             : 
      69             : /** retrieves the page that is currently painted. This will only be the master page
      70             :     if the current drawn view only shows the master page*/
      71        8589 : static SdPage* GetCurrentPage( sd::ViewShell* pViewSh, EditFieldInfo* pInfo, bool& bMasterView )
      72             : {
      73        8589 :     if( !pInfo )
      74           0 :         return 0;
      75             : 
      76        8589 :     bMasterView = false;
      77        8589 :     SdPage* pPage = dynamic_cast< SdPage* >( pInfo->GetSdrPage() );
      78        8589 :     SdrOutliner* pOutliner = dynamic_cast< SdrOutliner* >( pInfo->GetOutliner() );
      79             : 
      80             :     // special case, someone already set the current page on the EditFieldInfo
      81             :     // This is used from the svx::UnoGraphicsExporter f.e.
      82        8589 :     if( pPage )
      83             :     {
      84           0 :         bMasterView = false;
      85           0 :         return pPage;
      86             :     }
      87             : 
      88             :     // first try to check if we are inside the outline view
      89        8589 :     sd::OutlineView* pSdView = NULL;
      90        8589 :     if( pViewSh && pViewSh->ISA(sd::OutlineViewShell))
      91           0 :         pSdView = static_cast<sd::OutlineView*> (static_cast<sd::OutlineViewShell*>(pViewSh)->GetView());
      92             : 
      93        8589 :     if (pSdView != NULL && (pOutliner ==  &pSdView->GetOutliner()))
      94             :     {
      95             :         // outline mode
      96           0 :         int nPgNum = 0;
      97           0 :         Outliner& rOutl = pSdView->GetOutliner();
      98           0 :         long nPos = pInfo->GetPara();
      99           0 :         sal_Int32 nParaPos = 0;
     100             : 
     101           0 :         for( Paragraph* pPara = rOutl.GetParagraph( 0 ); pPara && nPos >= 0; pPara = rOutl.GetParagraph( ++nParaPos ), nPos-- )
     102             :         {
     103           0 :             if( Outliner::HasParaFlag( pPara, ParaFlag::ISPAGE ) )
     104           0 :                 nPgNum++;
     105             :         }
     106             : 
     107           0 :         pPage = pViewSh->GetDoc()->GetSdPage( (sal_uInt16)nPgNum, PK_STANDARD );
     108             :     }
     109             :     else
     110             :     {
     111             :         // draw mode, slide mode and preview. Get the processed page from the outliner
     112        8589 :         if(pOutliner)
     113             :         {
     114        8589 :             pPage = dynamic_cast< SdPage* >(const_cast< SdrPage* >(pOutliner->getVisualizedPage()));
     115             :         }
     116             : 
     117             :         // The path using GetPaintingPageView() and GetCurrentPaintingDisplayInfo()
     118             :         // is no longer needed. I debugged and checked all usages of PageNumber decompositions
     119             :         // which all use the new possibility of setting the visualized page at the SdrOutliner.
     120             : 
     121             :         // if all else failed, geht the current page from the object that is
     122             :         // currently formatted from the document
     123        8589 :         if(!pPage)
     124             :         {
     125        8454 :             const SdrTextObj* pTextObj = (pViewSh && pViewSh->GetDoc()) ? pViewSh->GetDoc()->GetFormattingTextObj() : NULL;
     126             : 
     127        8454 :             if( pTextObj )
     128             :             {
     129         553 :                 pPage = dynamic_cast< SdPage* >( pTextObj->GetPage() );
     130             :             }
     131             :         }
     132             : 
     133        8589 :         if(pPage)
     134             :         {
     135         688 :             bMasterView = pPage && pPage->IsMasterPage();
     136             :         }
     137             :     }
     138             : 
     139        8589 :     return pPage;
     140             : }
     141             : 
     142             : /**
     143             :  * Link for CalcFieldValue of Outliners
     144             :  */
     145       17284 : IMPL_LINK(SdModule, CalcFieldValueHdl, EditFieldInfo*, pInfo)
     146             : {
     147        8642 :     if (pInfo)
     148             :     {
     149        8642 :         const SvxFieldData* pField = pInfo->GetField().GetField();
     150        8642 :         ::sd::DrawDocShell*     pDocShell = NULL;
     151        8642 :         SdDrawDocument* pDoc = 0;
     152             : 
     153        8642 :         SdrOutliner* pSdrOutliner = dynamic_cast< SdrOutliner* >( pInfo->GetOutliner() );
     154        8642 :         if( pSdrOutliner )
     155             :         {
     156        8642 :             const SdrTextObj* pTextObj = pSdrOutliner->GetTextObj();
     157             : 
     158        8642 :             if( pTextObj )
     159        8532 :                 pDoc = dynamic_cast< SdDrawDocument* >( pTextObj->GetModel() );
     160             : 
     161        8642 :             if( pDoc )
     162        8532 :                 pDocShell = pDoc->GetDocSh();
     163             :         }
     164             : 
     165        8642 :         if( !pDocShell )
     166         110 :             pDocShell = dynamic_cast< ::sd::DrawDocShell *>( SfxObjectShell::Current() );
     167             : 
     168        8642 :         const SvxDateField* pDateField = 0;
     169        8642 :         const SvxExtTimeField* pExtTimeField = 0;
     170        8642 :         const SvxExtFileField* pExtFileField = 0;
     171        8642 :         const SvxAuthorField* pAuthorField = 0;
     172        8642 :         const SvxURLField* pURLField = 0;
     173             : 
     174        8642 :         if( (pDateField = dynamic_cast< const SvxDateField* >(pField)) != 0 )
     175             :         {
     176          53 :             LanguageType eLang = pInfo->GetOutliner()->GetLanguage( pInfo->GetPara(), pInfo->GetPos() );
     177          53 :             pInfo->SetRepresentation( pDateField->GetFormatted( *GetNumberFormatter(), eLang ) );
     178             :         }
     179        8589 :         else if( (pExtTimeField = dynamic_cast< const SvxExtTimeField *>(pField)) != 0 )
     180             :         {
     181           0 :             LanguageType eLang = pInfo->GetOutliner()->GetLanguage( pInfo->GetPara(), pInfo->GetPos() );
     182           0 :             pInfo->SetRepresentation( pExtTimeField->GetFormatted( *GetNumberFormatter(), eLang ) );
     183             :         }
     184        8589 :         else if( (pExtFileField = dynamic_cast< const SvxExtFileField * >(pField)) != 0 )
     185             :         {
     186           0 :             if( pDocShell && (pExtFileField->GetType() != SVXFILETYPE_FIX) )
     187             :             {
     188           0 :                 OUString aName;
     189           0 :                 if( pDocShell->HasName() )
     190           0 :                     aName = pDocShell->GetMedium()->GetName();
     191             :                 else
     192           0 :                     aName = pDocShell->GetName();
     193             : 
     194           0 :                 const_cast< SvxExtFileField* >(pExtFileField)->SetFile( aName );
     195             :             }
     196           0 :             pInfo->SetRepresentation( pExtFileField->GetFormatted() );
     197             : 
     198             :         }
     199        8589 :         else if( (pAuthorField = dynamic_cast< const SvxAuthorField* >( pField )) != 0  )
     200             :         {
     201           0 :             if( pAuthorField->GetType() != SVXAUTHORTYPE_FIX )
     202             :             {
     203           0 :                 SvtUserOptions aUserOptions;
     204             :                 SvxAuthorField aAuthorField(
     205             :                         aUserOptions.GetFirstName(), aUserOptions.GetLastName(), aUserOptions.GetID(),
     206           0 :                         pAuthorField->GetType(), pAuthorField->GetFormat() );
     207             : 
     208           0 :                 *(const_cast< SvxAuthorField* >(pAuthorField)) = aAuthorField;
     209             :             }
     210           0 :             pInfo->SetRepresentation( pAuthorField->GetFormatted() );
     211             : 
     212             :         }
     213        8589 :         else if( dynamic_cast< const SvxPageField*  >(pField) )
     214             :         {
     215        2460 :             OUString aRepresentation(" ");
     216             : 
     217        2460 :             ::sd::ViewShell* pViewSh = pDocShell ? pDocShell->GetViewShell() : NULL;
     218        2460 :             if(pViewSh == NULL)
     219             :             {
     220        2291 :                 ::sd::ViewShellBase* pBase = PTR_CAST(::sd::ViewShellBase, SfxViewShell::Current());
     221        2291 :                 if(pBase)
     222           2 :                     pViewSh = pBase->GetMainViewShell().get();
     223             :             }
     224        2460 :             if( !pDoc && pViewSh )
     225          30 :                 pDoc = pViewSh->GetDoc();
     226             : 
     227             :             bool bMasterView;
     228        2460 :             SdPage* pPage = GetCurrentPage( pViewSh, pInfo, bMasterView );
     229             : 
     230        2460 :             if( pPage && pDoc && !bMasterView )
     231             :             {
     232             :                 int nPgNum;
     233             : 
     234          19 :                 if( (pPage->GetPageKind() == PK_HANDOUT) && pViewSh )
     235             :                 {
     236           0 :                     nPgNum = pViewSh->GetPrintedHandoutPageNum();
     237             :                 }
     238             :                 else
     239             :                 {
     240          19 :                     nPgNum = (pPage->GetPageNum() - 1) / 2 + 1;
     241             :                 }
     242          19 :                 aRepresentation = pDoc->CreatePageNumValue((sal_uInt16)nPgNum);
     243             :             }
     244             :             else
     245        2441 :                 aRepresentation = SdResId(STR_FIELD_PLACEHOLDER_NUMBER).toString();
     246             : 
     247        2460 :             pInfo->SetRepresentation( aRepresentation );
     248             :         }
     249             : 
     250        6129 :         else if( dynamic_cast< const SvxPageTitleField*  >(pField) )
     251             :         {
     252           0 :             OUString aRepresentation(" ");
     253             : 
     254           0 :             ::sd::ViewShell* pViewSh = pDocShell ? pDocShell->GetViewShell() : NULL;
     255           0 :             if(pViewSh == NULL)
     256             :             {
     257           0 :                 ::sd::ViewShellBase* pBase = PTR_CAST(::sd::ViewShellBase, SfxViewShell::Current());
     258           0 :                 if(pBase)
     259           0 :                     pViewSh = pBase->GetMainViewShell().get();
     260             :             }
     261           0 :             if( !pDoc && pViewSh )
     262           0 :                 pDoc = pViewSh->GetDoc();
     263             : 
     264             :             bool bMasterView;
     265           0 :             SdPage* pPage = GetCurrentPage( pViewSh, pInfo, bMasterView );
     266             : 
     267           0 :             if( pPage && pDoc && !bMasterView )
     268             :             {
     269           0 :                 aRepresentation = pPage->GetName();
     270             :             }
     271             :             else
     272             :             {
     273           0 :                 aRepresentation = ( ( pDoc->GetDocumentType() == DOCUMENT_TYPE_IMPRESS )
     274             :                                     ? SdResId(STR_FIELD_PLACEHOLDER_SLIDENAME).toString()
     275           0 :                                     : SdResId(STR_FIELD_PLACEHOLDER_PAGENAME).toString() );
     276             :             }
     277             : 
     278           0 :             pInfo->SetRepresentation( aRepresentation );
     279             :         }
     280        6129 :         else if( dynamic_cast< const SvxPagesField*  >(pField) )
     281             :         {
     282           0 :             OUString aRepresentation(" ");
     283             : 
     284           0 :             ::sd::ViewShell* pViewSh = pDocShell ? pDocShell->GetViewShell() : NULL;
     285           0 :             if(pViewSh == NULL)
     286             :             {
     287           0 :                 ::sd::ViewShellBase* pBase = PTR_CAST(::sd::ViewShellBase, SfxViewShell::Current());
     288           0 :                 if(pBase)
     289           0 :                     pViewSh = pBase->GetMainViewShell().get();
     290             :             }
     291           0 :             if( !pDoc && pViewSh )
     292           0 :                 pDoc = pViewSh->GetDoc();
     293             : 
     294             :             bool bMasterView;
     295           0 :             SdPage* pPage = GetCurrentPage( pViewSh, pInfo, bMasterView );
     296             : 
     297           0 :             sal_uInt16 nPageCount = 0;
     298             : 
     299           0 :             if( !bMasterView )
     300             :             {
     301           0 :                 if( pPage && (pPage->GetPageKind() == PK_HANDOUT) && pViewSh )
     302             :                 {
     303           0 :                     nPageCount = pViewSh->GetPrintedHandoutPageCount();
     304             :                 }
     305           0 :                 else if( pDoc )
     306             :                 {
     307           0 :                     nPageCount = (sal_uInt16)pDoc->GetActiveSdPageCount();
     308             :                 }
     309             :             }
     310             : 
     311           0 :             if( nPageCount > 0 )
     312           0 :                 aRepresentation = pDoc->CreatePageNumValue(nPageCount);
     313             :             else
     314           0 :                 aRepresentation = SdResId(STR_FIELD_PLACEHOLDER_COUNT).toString();
     315             : 
     316           0 :             pInfo->SetRepresentation( aRepresentation );
     317             :         }
     318        6129 :         else if( (pURLField = dynamic_cast< const SvxURLField* >(pField)) != 0 )
     319             :         {
     320           0 :             switch ( pURLField->GetFormat() )
     321             :             {
     322             :                 case SVXURLFORMAT_APPDEFAULT: //!!! adjustable at App???
     323             :                 case SVXURLFORMAT_REPR:
     324           0 :                     pInfo->SetRepresentation( pURLField->GetRepresentation() );
     325           0 :                     break;
     326             : 
     327             :                 case SVXURLFORMAT_URL:
     328           0 :                     pInfo->SetRepresentation( pURLField->GetURL() );
     329           0 :                     break;
     330             :             }
     331             : 
     332           0 :             OUString aURL = pURLField->GetURL();
     333             : 
     334           0 :             svtools::ColorConfig aConfig;
     335             :             svtools::ColorConfigEntry eEntry =
     336           0 :                 INetURLHistory::GetOrCreate()->QueryUrl( aURL ) ? svtools::LINKSVISITED : svtools::LINKS;
     337           0 :             pInfo->SetTextColor( aConfig.GetColorValue(eEntry).nColor );
     338             :         }
     339        6129 :         else if ( dynamic_cast< const SdrMeasureField* >(pField))
     340             :         {
     341           0 :             pInfo->ClearFieldColor();
     342             :         }
     343             :         else
     344             :         {
     345        6129 :             OUString aRepresentation;
     346             : 
     347        6129 :             bool bHeaderField = dynamic_cast< const SvxHeaderField* >( pField ) != 0;
     348        6129 :             bool bFooterField = !bHeaderField && (dynamic_cast< const SvxFooterField* >( pField ) != 0 );
     349        6129 :             bool bDateTimeField = !bHeaderField && !bFooterField && (dynamic_cast< const SvxDateTimeField* >( pField ) != 0);
     350             : 
     351        6129 :             if( bHeaderField || bFooterField || bDateTimeField )
     352             :             {
     353        6129 :                 sd::ViewShell* pViewSh = pDocShell ? pDocShell->GetViewShell() : NULL;
     354        6129 :                 bool bMasterView = false;
     355        6129 :                 SdPage* pPage = GetCurrentPage( pViewSh, pInfo, bMasterView );
     356             : 
     357        6129 :                 if( (pPage == NULL) || bMasterView )
     358             :                 {
     359       11900 :                     if( bHeaderField )
     360        1349 :                         aRepresentation = SdResId(STR_FIELD_PLACEHOLDER_HEADER).toString();
     361        4601 :                     else if (bFooterField )
     362        2303 :                         aRepresentation = SdResId(STR_FIELD_PLACEHOLDER_FOOTER).toString();
     363        2298 :                     else if (bDateTimeField )
     364        2298 :                         aRepresentation = SdResId(STR_FIELD_PLACEHOLDER_DATETIME).toString();
     365             :                 }
     366             :                 else
     367             :                 {
     368         179 :                     const sd::HeaderFooterSettings &rSettings = pPage->getHeaderFooterSettings();
     369             : 
     370         179 :                     if( bHeaderField )
     371             :                     {
     372          15 :                         aRepresentation = rSettings.maHeaderText;
     373             :                     }
     374         164 :                     else if( bFooterField )
     375             :                     {
     376          82 :                         aRepresentation = rSettings.maFooterText;
     377             :                     }
     378          82 :                     else if( bDateTimeField )
     379             :                     {
     380          82 :                         if( rSettings.mbDateTimeIsFixed )
     381             :                         {
     382          82 :                             aRepresentation = rSettings.maDateTimeText;
     383             :                         }
     384             :                         else
     385             :                         {
     386           0 :                             Date aDate( Date::SYSTEM );
     387           0 :                             tools::Time aTime( tools::Time::SYSTEM );
     388           0 :                             LanguageType eLang = pInfo->GetOutliner()->GetLanguage( pInfo->GetPara(), pInfo->GetPos() );
     389           0 :                             aRepresentation = SvxDateTimeField::GetFormatted( aDate, aTime, (SvxDateFormat)rSettings.meDateTimeFormat, *GetNumberFormatter(), eLang );
     390             :                         }
     391             :                     }
     392             :                 }
     393             :             }
     394             :             else
     395             :             {
     396             :                 OSL_FAIL("sd::SdModule::CalcFieldValueHdl(), unknown field type!");
     397             :             }
     398             : 
     399        6129 :             if( aRepresentation.isEmpty() )                // TODO: Edit engine doesn't handle empty fields?
     400         179 :                 aRepresentation = " ";
     401        6129 :             pInfo->SetRepresentation( aRepresentation );
     402             :         }
     403             :     }
     404             : 
     405        8642 :     return 0;
     406             : }
     407             : 
     408             : /**
     409             :  * virtual methods for option dialog
     410             :  */
     411           0 : SfxItemSet*  SdModule::CreateItemSet( sal_uInt16 nSlot )
     412             : {
     413           0 :     ::sd::FrameView* pFrameView = NULL;
     414           0 :     ::sd::DrawDocShell* pDocSh = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current() );
     415           0 :     SdDrawDocument* pDoc = NULL;
     416             : 
     417             :     // Here we set the DocType of the option dialog (not document!)
     418           0 :     DocumentType eDocType = DOCUMENT_TYPE_IMPRESS;
     419           0 :     if( nSlot == SID_SD_GRAPHIC_OPTIONS )
     420           0 :         eDocType = DOCUMENT_TYPE_DRAW;
     421             : 
     422           0 :     if (pDocSh)
     423             :     {
     424           0 :         pDoc = pDocSh->GetDoc();
     425             : 
     426             :         // If the option dialog is identical to the document type,
     427             :         // we can pass the FrameView too:
     428           0 :         if( pDoc && eDocType == pDoc->GetDocumentType() )
     429           0 :             pFrameView = pDocSh->GetFrameView();
     430             : 
     431           0 :         ::sd::ViewShell* pViewShell = pDocSh->GetViewShell();
     432           0 :         if (pViewShell != NULL)
     433           0 :             pViewShell->WriteFrameViewData();
     434             :     }
     435             : 
     436           0 :     SdOptions* pOptions = GetSdOptions(eDocType);
     437             : 
     438             :     // Pool has by default MapUnit Twips (Awgh!)
     439           0 :     SfxItemPool& rPool = GetPool();
     440           0 :     rPool.SetDefaultMetric( SFX_MAPUNIT_100TH_MM );
     441             : 
     442             :     SfxItemSet*  pRet = new SfxItemSet( rPool,
     443             :                         SID_ATTR_METRIC, SID_ATTR_METRIC,
     444             :                         SID_ATTR_DEFTABSTOP, SID_ATTR_DEFTABSTOP,
     445             : 
     446             :                         ATTR_OPTIONS_LAYOUT, ATTR_OPTIONS_LAYOUT,
     447             :                         ATTR_OPTIONS_CONTENTS, ATTR_OPTIONS_CONTENTS,
     448             :                         ATTR_OPTIONS_MISC, ATTR_OPTIONS_MISC,
     449             : 
     450             :                         ATTR_OPTIONS_SNAP, ATTR_OPTIONS_SNAP,
     451             : 
     452             :                         ATTR_OPTIONS_SCALE_START, ATTR_OPTIONS_SCALE_END,
     453             : 
     454             :                         ATTR_OPTIONS_PRINT, ATTR_OPTIONS_PRINT,
     455             : 
     456             :                         SID_ATTR_GRID_OPTIONS, SID_ATTR_GRID_OPTIONS,
     457           0 :                         0 );
     458             : 
     459             :     // TP_OPTIONS_LAYOUT:
     460           0 :     pRet->Put( SdOptionsLayoutItem( ATTR_OPTIONS_LAYOUT, pOptions, pFrameView ) );
     461             : 
     462           0 :     sal_uInt16 nDefTab = 0;
     463           0 :     if( pFrameView)
     464           0 :         nDefTab = pDoc->GetDefaultTabulator();
     465             :     else
     466           0 :         nDefTab = pOptions->GetDefTab();
     467           0 :     pRet->Put( SfxUInt16Item( SID_ATTR_DEFTABSTOP, nDefTab ) );
     468             : 
     469           0 :     FieldUnit nMetric = (FieldUnit)0xffff;
     470           0 :     if( pFrameView)
     471           0 :         nMetric = pDoc->GetUIUnit();
     472             :     else
     473           0 :         nMetric = (FieldUnit)pOptions->GetMetric();
     474             : 
     475           0 :     if( nMetric == (FieldUnit)0xffff )
     476           0 :         nMetric = GetFieldUnit();
     477             : 
     478           0 :     pRet->Put( SfxUInt16Item( SID_ATTR_METRIC, (sal_uInt16)nMetric ) );
     479             : 
     480             :     // TP_OPTIONS_CONTENTS:
     481           0 :     pRet->Put( SdOptionsContentsItem( ATTR_OPTIONS_CONTENTS, pOptions, pFrameView ) );
     482             : 
     483             :     // TP_OPTIONS_MISC:
     484           0 :     SdOptionsMiscItem aSdOptionsMiscItem( ATTR_OPTIONS_MISC, pOptions, pFrameView );
     485           0 :     if ( pFrameView )
     486             :     {
     487           0 :         aSdOptionsMiscItem.GetOptionsMisc().SetSummationOfParagraphs( pDoc->IsSummationOfParagraphs() );
     488           0 :         aSdOptionsMiscItem.GetOptionsMisc().SetPrinterIndependentLayout (
     489           0 :             (sal_uInt16)pDoc->GetPrinterIndependentLayout());
     490             :     }
     491           0 :     pRet->Put( aSdOptionsMiscItem );
     492             : 
     493             :     // TP_OPTIONS_SNAP:
     494           0 :     pRet->Put( SdOptionsSnapItem( ATTR_OPTIONS_SNAP, pOptions, pFrameView ) );
     495             : 
     496             :     // TP_SCALE:
     497           0 :     sal_uInt32 nW = 10L;
     498           0 :     sal_uInt32 nH = 10L;
     499             :     sal_Int32  nX;
     500             :     sal_Int32  nY;
     501           0 :     if( pDocSh )
     502             :     {
     503           0 :         SdrPage* pPage = static_cast<SdrPage*>(pDoc->GetSdPage(0, PK_STANDARD));
     504           0 :         Size aSize(pPage->GetSize());
     505           0 :         nW = aSize.Width();
     506           0 :         nH = aSize.Height();
     507             :     }
     508             : 
     509           0 :     if(pFrameView)
     510             :     {
     511           0 :         const Fraction& rFraction =  pDoc->GetUIScale();
     512           0 :         nX=rFraction.GetNumerator();
     513           0 :         nY=rFraction.GetDenominator();
     514             :     }
     515             :     else
     516             :     {
     517             :         // Get options from configuration file
     518           0 :         pOptions->GetScale( nX, nY );
     519             :     }
     520             : 
     521           0 :     pRet->Put( SfxInt32Item( ATTR_OPTIONS_SCALE_X, nX ) );
     522           0 :     pRet->Put( SfxInt32Item( ATTR_OPTIONS_SCALE_Y, nY ) );
     523           0 :     pRet->Put( SfxUInt32Item( ATTR_OPTIONS_SCALE_WIDTH, nW ) );
     524           0 :     pRet->Put( SfxUInt32Item( ATTR_OPTIONS_SCALE_HEIGHT, nH ) );
     525             : 
     526             :     // TP_OPTIONS_PRINT:
     527           0 :     pRet->Put( SdOptionsPrintItem( ATTR_OPTIONS_PRINT, pOptions ) );
     528             : 
     529             :     // RID_SVXPAGE_GRID:
     530           0 :     pRet->Put( SdOptionsGridItem( SID_ATTR_GRID_OPTIONS, pOptions ) );
     531             : 
     532           0 :     return pRet;
     533             : }
     534           0 : void SdModule::ApplyItemSet( sal_uInt16 nSlot, const SfxItemSet& rSet )
     535             : {
     536           0 :     const SfxPoolItem*  pItem = NULL;
     537           0 :     bool bNewDefTab = false;
     538           0 :     bool bNewPrintOptions = false;
     539           0 :     bool bMiscOptions = false;
     540             : 
     541           0 :     ::sd::DrawDocShell* pDocSh = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current() );
     542           0 :     SdDrawDocument* pDoc = NULL;
     543             :     // Here we set the DocType of the option dialog (not document!)
     544           0 :     DocumentType eDocType = DOCUMENT_TYPE_IMPRESS;
     545           0 :     if( nSlot == SID_SD_GRAPHIC_OPTIONS )
     546           0 :         eDocType = DOCUMENT_TYPE_DRAW;
     547             : 
     548           0 :     ::sd::ViewShell* pViewShell = NULL;
     549             : 
     550           0 :     if (pDocSh)
     551             :     {
     552           0 :         pDoc = pDocSh->GetDoc();
     553             : 
     554           0 :         pViewShell = pDocSh->GetViewShell();
     555           0 :         if (pViewShell != NULL)
     556           0 :             pViewShell->WriteFrameViewData();
     557             :     }
     558           0 :     SdOptions* pOptions = GetSdOptions(eDocType);
     559             :     // Grid
     560           0 :     if( SfxItemState::SET == rSet.GetItemState( SID_ATTR_GRID_OPTIONS ,
     561           0 :                             false, &pItem ))
     562             :     {
     563           0 :         const SdOptionsGridItem* pGridItem = static_cast<const SdOptionsGridItem*>(pItem);
     564           0 :         pGridItem->SetOptions( pOptions );
     565             :     }
     566             : 
     567             :     // Layout
     568           0 :     const SdOptionsLayoutItem* pLayoutItem = NULL;
     569           0 :     if( SfxItemState::SET == rSet.GetItemState( ATTR_OPTIONS_LAYOUT,
     570           0 :                             false, reinterpret_cast<const SfxPoolItem**>(&pLayoutItem) ))
     571             :     {
     572           0 :         pLayoutItem->SetOptions( pOptions );
     573             :     }
     574             : 
     575             :     // Metric
     576           0 :     if( SfxItemState::SET == rSet.GetItemState( SID_ATTR_METRIC, false, &pItem ) )
     577             :     {
     578           0 :         if( pDoc && eDocType == pDoc->GetDocumentType() )
     579           0 :             PutItem( *pItem );
     580           0 :         pOptions->SetMetric( static_cast<const SfxUInt16Item*>( pItem )->GetValue() );
     581             :     }
     582           0 :     sal_uInt16 nDefTab = pOptions->GetDefTab();
     583             :     // Default-Tabulator
     584           0 :     if( SfxItemState::SET == rSet.GetItemState( SID_ATTR_DEFTABSTOP, false, &pItem ) )
     585             :     {
     586           0 :         nDefTab = static_cast<const SfxUInt16Item*>( pItem )->GetValue();
     587           0 :         pOptions->SetDefTab( nDefTab );
     588             : 
     589           0 :         bNewDefTab = true;
     590             :     }
     591             : 
     592             :     // Scale
     593           0 :     if( SfxItemState::SET == rSet.GetItemState( ATTR_OPTIONS_SCALE_X, false, &pItem ) )
     594             :     {
     595           0 :         sal_Int32 nX = static_cast<const SfxInt32Item*>( pItem )->GetValue();
     596           0 :         if( SfxItemState::SET == rSet.GetItemState( ATTR_OPTIONS_SCALE_Y, false, &pItem ) )
     597             :         {
     598           0 :             sal_Int32 nY = static_cast<const SfxInt32Item*>( pItem )->GetValue();
     599           0 :             pOptions->SetScale( nX, nY );
     600             : 
     601             :             // Apply to document only if doc type match
     602           0 :             if( pDocSh && pDoc && eDocType == pDoc->GetDocumentType() )
     603             :             {
     604           0 :                 pDoc->SetUIScale( Fraction( nX, nY ) );
     605           0 :                 if( pViewShell )
     606           0 :                     pViewShell->SetRuler( pViewShell->HasRuler() );
     607             :             }
     608             :         }
     609             :     }
     610             : 
     611             :     // Misc
     612           0 :     const SdOptionsMiscItem* pMiscItem = NULL;
     613           0 :     if( SfxItemState::SET == rSet.GetItemState( ATTR_OPTIONS_MISC,
     614           0 :                             false, reinterpret_cast<const SfxPoolItem**>(&pMiscItem) ))
     615             :     {
     616           0 :         pMiscItem->SetOptions( pOptions );
     617           0 :         bMiscOptions = true;
     618             :     }
     619             : 
     620             :     // Snap
     621           0 :     const SdOptionsSnapItem* pSnapItem = NULL;
     622           0 :     if( SfxItemState::SET == rSet.GetItemState( ATTR_OPTIONS_SNAP,
     623           0 :                             false, reinterpret_cast<const SfxPoolItem**>(&pSnapItem) ))
     624             :     {
     625           0 :         pSnapItem->SetOptions( pOptions );
     626             :     }
     627             : 
     628           0 :     SfxItemSet aPrintSet( GetPool(),
     629             :                     SID_PRINTER_NOTFOUND_WARN,  SID_PRINTER_NOTFOUND_WARN,
     630             :                     SID_PRINTER_CHANGESTODOC,   SID_PRINTER_CHANGESTODOC,
     631             :                     ATTR_OPTIONS_PRINT,         ATTR_OPTIONS_PRINT,
     632           0 :                     0 );
     633             : 
     634             :     // Print
     635           0 :     const SdOptionsPrintItem* pPrintItem = NULL;
     636           0 :     if( SfxItemState::SET == rSet.GetItemState( ATTR_OPTIONS_PRINT,
     637           0 :                             false, reinterpret_cast<const SfxPoolItem**>(&pPrintItem) ))
     638             :     {
     639           0 :         pPrintItem->SetOptions( pOptions );
     640             : 
     641             :         // set PrintOptionsSet
     642           0 :         SdOptionsPrintItem aPrintItem( ATTR_OPTIONS_PRINT, pOptions );
     643           0 :         SfxFlagItem aFlagItem( SID_PRINTER_CHANGESTODOC );
     644             :         SfxPrinterChangeFlags nFlags =
     645           0 :                 (aPrintItem.GetOptionsPrint().IsWarningSize() ? SfxPrinterChangeFlags::CHG_SIZE : SfxPrinterChangeFlags::NONE) |
     646           0 :                 (aPrintItem.GetOptionsPrint().IsWarningOrientation() ? SfxPrinterChangeFlags::CHG_ORIENTATION : SfxPrinterChangeFlags::NONE);
     647           0 :         aFlagItem.SetValue( static_cast<int>(nFlags) );
     648             : 
     649           0 :         aPrintSet.Put( aPrintItem );
     650           0 :         aPrintSet.Put( SfxBoolItem( SID_PRINTER_NOTFOUND_WARN, aPrintItem.GetOptionsPrint().IsWarningPrinter() ) );
     651           0 :         aPrintSet.Put( aFlagItem );
     652             : 
     653           0 :         bNewPrintOptions = true;
     654             :     }
     655             : 
     656             :     // Only if also the document type matches...
     657           0 :     if( pDocSh && pDoc && eDocType == pDoc->GetDocumentType() )
     658             :     {
     659           0 :         if( bNewPrintOptions )
     660             :         {
     661           0 :             pDocSh->GetPrinter(true)->SetOptions( aPrintSet );
     662             :         }
     663             : 
     664             :         // set DefTab at Model
     665           0 :         if( bNewDefTab )
     666             :         {
     667           0 :             SdDrawDocument* pDocument = pDocSh->GetDoc();
     668           0 :             pDocument->SetDefaultTabulator( nDefTab );
     669             : 
     670           0 :             ::sd::Outliner* pOutl = pDocument->GetOutliner( false );
     671           0 :             if( pOutl )
     672           0 :                 pOutl->SetDefTab( nDefTab );
     673             : 
     674           0 :             ::sd::Outliner* pInternalOutl = pDocument->GetInternalOutliner( false );
     675           0 :             if( pInternalOutl )
     676           0 :                 pInternalOutl->SetDefTab( nDefTab );
     677             :         }
     678           0 :         if ( bMiscOptions )
     679             :         {
     680           0 :             pDoc->SetSummationOfParagraphs( pMiscItem->GetOptionsMisc().IsSummationOfParagraphs() );
     681           0 :             EEControlBits nSum = pMiscItem->GetOptionsMisc().IsSummationOfParagraphs() ? EEControlBits::ULSPACESUMMATION : EEControlBits::NONE;
     682             :             EEControlBits nCntrl;
     683             : 
     684           0 :             SdDrawDocument* pDocument = pDocSh->GetDoc();
     685           0 :             SdrOutliner& rOutl = pDocument->GetDrawOutliner();
     686           0 :             nCntrl = rOutl.GetControlWord() &~ EEControlBits::ULSPACESUMMATION;
     687           0 :             rOutl.SetControlWord( nCntrl | nSum );
     688           0 :             ::sd::Outliner* pOutl = pDocument->GetOutliner( false );
     689           0 :             if( pOutl )
     690             :             {
     691           0 :                 nCntrl = pOutl->GetControlWord() &~ EEControlBits::ULSPACESUMMATION;
     692           0 :                 pOutl->SetControlWord( nCntrl | nSum );
     693             :             }
     694           0 :             pOutl = pDocument->GetInternalOutliner( false );
     695           0 :             if( pOutl )
     696             :             {
     697           0 :                 nCntrl = pOutl->GetControlWord() &~ EEControlBits::ULSPACESUMMATION;
     698           0 :                 pOutl->SetControlWord( nCntrl | nSum );
     699             :             }
     700             : 
     701             :             // Set printer independent layout mode.
     702           0 :             if( pDoc->GetPrinterIndependentLayout() != pMiscItem->GetOptionsMisc().GetPrinterIndependentLayout() )
     703           0 :                 pDoc->SetPrinterIndependentLayout (pMiscItem->GetOptionsMisc().GetPrinterIndependentLayout());
     704             :         }
     705             :     }
     706             : 
     707           0 :     pOptions->StoreConfig();
     708             : 
     709             :     // Only if also the document type matches...
     710           0 :     if( pDocSh && pDoc && eDocType == pDoc->GetDocumentType() )
     711             :     {
     712           0 :         FieldUnit eUIUnit = (FieldUnit) pOptions->GetMetric();
     713           0 :         pDoc->SetUIUnit(eUIUnit);
     714             : 
     715           0 :         if (pViewShell)
     716             :         {
     717             :             // make sure no one is in text edit mode, cause there
     718             :             // are some pointers remembered else (!)
     719           0 :             if(pViewShell->GetView())
     720           0 :                 pViewShell->GetView()->SdrEndTextEdit();
     721             : 
     722           0 :             ::sd::FrameView* pFrame = pViewShell->GetFrameView();
     723           0 :             pFrame->Update(pOptions);
     724           0 :             pViewShell->ReadFrameViewData(pFrame);
     725           0 :             pViewShell->SetUIUnit(eUIUnit);
     726           0 :             pViewShell->SetDefTabHRuler( nDefTab );
     727             :         }
     728             :     }
     729             : 
     730           0 :     if( pViewShell && pViewShell->GetViewFrame() )
     731           0 :         pViewShell->GetViewFrame()->GetBindings().InvalidateAll( true );
     732           0 : }
     733             : 
     734           0 : VclPtr<SfxTabPage> SdModule::CreateTabPage( sal_uInt16 nId, vcl::Window* pParent, const SfxItemSet& rSet )
     735             : {
     736           0 :     VclPtr<SfxTabPage> pRet;
     737           0 :     SfxAllItemSet aSet(*(rSet.GetPool()));
     738           0 :     SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
     739           0 :     if( pFact )
     740             :     {
     741           0 :         switch(nId)
     742             :         {
     743             :             case SID_SD_TP_CONTENTS:
     744             :             case SID_SI_TP_CONTENTS:
     745           0 :             {   ::CreateTabPage fnCreatePage = pFact->GetSdOptionsContentsTabPageCreatorFunc();
     746           0 :                 if( fnCreatePage )
     747           0 :                     pRet = (*fnCreatePage)( pParent, &rSet );
     748             :             }
     749           0 :             break;
     750             :             case SID_SD_TP_SNAP:
     751             :             case SID_SI_TP_SNAP:
     752           0 :             {   ::CreateTabPage fnCreatePage = pFact->GetSdOptionsSnapTabPageCreatorFunc();
     753           0 :                 if( fnCreatePage )
     754           0 :                     pRet = (*fnCreatePage)( pParent, &rSet );
     755             :             }
     756           0 :             break;
     757             :             case SID_SD_TP_PRINT:
     758             :             case SID_SI_TP_PRINT:
     759             :             {
     760           0 :                 ::CreateTabPage fnCreatePage = pFact->GetSdPrintOptionsTabPageCreatorFunc();
     761           0 :                 if( fnCreatePage )
     762             :                 {
     763           0 :                     pRet = (*fnCreatePage)( pParent, &rSet );
     764           0 :                     if(SID_SD_TP_PRINT == nId)
     765           0 :                         aSet.Put (SfxUInt32Item(SID_SDMODE_FLAG,SD_DRAW_MODE));
     766           0 :                     pRet->PageCreated(aSet);
     767             :                 }
     768             :             }
     769           0 :             break;
     770             :             case SID_SI_TP_MISC:
     771             :             case SID_SD_TP_MISC:
     772             :             {
     773           0 :                 ::CreateTabPage fnCreatePage = pFact->GetSdOptionsMiscTabPageCreatorFunc();
     774           0 :                 if( fnCreatePage )
     775             :                 {
     776           0 :                     pRet = (*fnCreatePage)( pParent, &rSet );
     777           0 :                     if(SID_SD_TP_MISC == nId)
     778           0 :                         aSet.Put (SfxUInt32Item(SID_SDMODE_FLAG,SD_DRAW_MODE));
     779             :                     else
     780           0 :                         aSet.Put (SfxUInt32Item(SID_SDMODE_FLAG,SD_IMPRESS_MODE));
     781           0 :                     pRet->PageCreated(aSet);
     782             :                 }
     783             :             }
     784           0 :             break;
     785             :             case RID_SVXPAGE_TEXTANIMATION :
     786             :             {
     787           0 :                 SfxAbstractDialogFactory* pSfxFact = SfxAbstractDialogFactory::Create();
     788           0 :                 if ( pSfxFact )
     789             :                 {
     790           0 :                     ::CreateTabPage fnCreatePage = pSfxFact->GetTabPageCreatorFunc( nId );
     791           0 :                     if ( fnCreatePage )
     792           0 :                         pRet = (*fnCreatePage)( pParent, &rSet );
     793             :                 }
     794             :             }
     795           0 :             break;
     796             :         }
     797             :         DBG_ASSERT( pRet, "SdModule::CreateTabPage(): no valid ID for TabPage!" );
     798             :     }
     799             : 
     800           0 :     return pRet;
     801          66 : }
     802             : 
     803             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11