LCOV - code coverage report
Current view: top level - libreoffice/sd/source/ui/docshell - docshel2.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 7 199 3.5 %
Date: 2012-12-17 Functions: 3 13 23.1 %
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             : 
      21             : #include "DrawDocShell.hxx"
      22             : #include <vcl/msgbox.hxx>
      23             : #include <svx/svdpagv.hxx>
      24             : #include <svx/svxdlg.hxx>
      25             : #include <svx/dialogs.hrc>
      26             : 
      27             : #include "helpids.h"
      28             : #include "ViewShell.hxx"
      29             : #include "drawview.hxx"
      30             : #include "FrameView.hxx"
      31             : #include "drawdoc.hxx"
      32             : #include "sdpage.hxx"
      33             : #include "View.hxx"
      34             : #include "ClientView.hxx"
      35             : #include "Window.hxx"
      36             : #include "strings.hrc"
      37             : #include "res_bmp.hrc"
      38             : #include "sdresid.hxx"
      39             : #include "strmname.h"
      40             : #include "fupoor.hxx"
      41             : #include <vcl/svapp.hxx>
      42             : #include <vcl/virdev.hxx>
      43             : #include <comphelper/string.hxx>
      44             : 
      45             : namespace sd {
      46             : 
      47             : /*************************************************************************
      48             : |*
      49             : |* Zeichnen der DocShell (mittels der Hilfsklasse SdDrawViewShell)
      50             : |*
      51             : \************************************************************************/
      52             : 
      53           0 : void DrawDocShell::Draw(OutputDevice* pOut, const JobSetup&, sal_uInt16 nAspect)
      54             : {
      55             :     if (nAspect == ASPECT_THUMBNAIL)
      56             :     {
      57             :         /**********************************************************************
      58             :         * THUMBNAIL: Hier koennte ev. einmal der Draft-Mode gesetzt werden
      59             :         **********************************************************************/
      60             :     }
      61             : 
      62           0 :     ClientView* pView = new ClientView(this, pOut, NULL);
      63             : 
      64           0 :     pView->SetHlplVisible(sal_False);
      65           0 :     pView->SetGridVisible(sal_False);
      66           0 :     pView->SetBordVisible(sal_False);
      67           0 :     pView->SetPageVisible(sal_False);
      68           0 :     pView->SetGlueVisible(sal_False);
      69             : 
      70           0 :     SdPage* pSelectedPage = NULL;
      71             : 
      72           0 :     const std::vector<sd::FrameView*> &rViews = mpDoc->GetFrameViewList();
      73           0 :     if( !rViews.empty() )
      74             :     {
      75           0 :         sd::FrameView* pFrameView = rViews[0];
      76           0 :         if( pFrameView->GetPageKind() == PK_STANDARD )
      77             :         {
      78           0 :             sal_uInt16 nSelectedPage = pFrameView->GetSelectedPage();
      79           0 :             pSelectedPage = mpDoc->GetSdPage(nSelectedPage, PK_STANDARD);
      80             :         }
      81             :     }
      82             : 
      83           0 :     if( NULL == pSelectedPage )
      84             :     {
      85           0 :         SdPage* pPage = NULL;
      86           0 :         sal_uInt16 nPageCnt = (sal_uInt16) mpDoc->GetSdPageCount(PK_STANDARD);
      87             : 
      88           0 :         for (sal_uInt16 i = 0; i < nPageCnt; i++)
      89             :         {
      90           0 :             pPage = mpDoc->GetSdPage(i, PK_STANDARD);
      91             : 
      92           0 :             if ( pPage->IsSelected() )
      93           0 :                 pSelectedPage = pPage;
      94             :         }
      95             : 
      96           0 :         if( NULL == pSelectedPage )
      97           0 :             pSelectedPage = mpDoc->GetSdPage(0, PK_STANDARD);
      98             :     }
      99             : 
     100           0 :     Rectangle aVisArea = GetVisArea(nAspect);
     101           0 :     pOut->IntersectClipRegion(aVisArea);
     102           0 :     pView->ShowSdrPage(pSelectedPage);
     103             : 
     104           0 :     if (pOut->GetOutDevType() != OUTDEV_WINDOW)
     105             :     {
     106           0 :         MapMode aOldMapMode = pOut->GetMapMode();
     107             : 
     108           0 :         if (pOut->GetOutDevType() == OUTDEV_PRINTER)
     109             :         {
     110           0 :             MapMode aMapMode = aOldMapMode;
     111           0 :             Point aOrigin = aMapMode.GetOrigin();
     112           0 :             aOrigin.X() += 1;
     113           0 :             aOrigin.Y() += 1;
     114           0 :             aMapMode.SetOrigin(aOrigin);
     115           0 :             pOut->SetMapMode(aMapMode);
     116             :         }
     117             : 
     118           0 :         Region aRegion(aVisArea);
     119           0 :         pView->CompleteRedraw(pOut, aRegion);
     120             : 
     121           0 :         if (pOut->GetOutDevType() == OUTDEV_PRINTER)
     122             :         {
     123           0 :             pOut->SetMapMode(aOldMapMode);
     124           0 :         }
     125             :     }
     126             : 
     127           0 :     delete pView;
     128             : 
     129           0 : }
     130             : 
     131          68 : Rectangle DrawDocShell::GetVisArea(sal_uInt16 nAspect) const
     132             : {
     133          68 :     Rectangle aVisArea;
     134             : 
     135          68 :     if( ( ASPECT_THUMBNAIL == nAspect ) || ( ASPECT_DOCPRINT == nAspect ) )
     136             :     {
     137             :         // Groesse der ersten Seite herausgeben
     138           0 :         MapMode aSrcMapMode(MAP_PIXEL);
     139           0 :         MapMode aDstMapMode(MAP_100TH_MM);
     140           0 :         Size aSize = mpDoc->GetSdPage(0, PK_STANDARD)->GetSize();
     141           0 :         aSrcMapMode.SetMapUnit(MAP_100TH_MM);
     142             : 
     143           0 :         aSize = Application::GetDefaultDevice()->LogicToLogic(aSize, &aSrcMapMode, &aDstMapMode);
     144           0 :         aVisArea.SetSize(aSize);
     145             :     }
     146             :     else
     147             :     {
     148          68 :         aVisArea = SfxObjectShell::GetVisArea(nAspect);
     149             :     }
     150             : 
     151          68 :     if (aVisArea.IsEmpty() && mpViewShell)
     152             :     {
     153           0 :         Window* pWin = mpViewShell->GetActiveWindow();
     154             : 
     155           0 :         if (pWin)
     156             :         {
     157           0 :             aVisArea = pWin->PixelToLogic(Rectangle(Point(0,0), pWin->GetOutputSizePixel()));
     158             :         }
     159             :     }
     160             : 
     161          68 :     return (aVisArea);
     162             : }
     163             : 
     164             : /*************************************************************************
     165             : |*
     166             : |* ViewShell anmelden
     167             : |*
     168             : \************************************************************************/
     169             : 
     170           0 : void DrawDocShell::Connect(ViewShell* pViewSh)
     171             : {
     172           0 :     mpViewShell = pViewSh;
     173           0 : }
     174             : 
     175             : /*************************************************************************
     176             : |*
     177             : |* ViewShell abmelden
     178             : |*
     179             : \************************************************************************/
     180             : 
     181           0 : void DrawDocShell::Disconnect(ViewShell* pViewSh)
     182             : {
     183           0 :     if (mpViewShell == pViewSh)
     184             :     {
     185           0 :         mpViewShell = NULL;
     186             :     }
     187           0 : }
     188             : 
     189           0 : FrameView* DrawDocShell::GetFrameView()
     190             : {
     191           0 :     FrameView* pFrameView = NULL;
     192             : 
     193           0 :     if (mpViewShell)
     194             :     {
     195           0 :         pFrameView = mpViewShell->GetFrameView();
     196             :     }
     197             : 
     198           0 :     return(pFrameView);
     199             : }
     200             : 
     201             : /*************************************************************************
     202             : |*
     203             : |* Groesse der ersten Seite zurueckgeben
     204             : |*
     205             : \************************************************************************/
     206             : 
     207           0 : Size DrawDocShell::GetFirstPageSize()
     208             : {
     209           0 :     return SfxObjectShell::GetFirstPageSize();
     210             : }
     211             : 
     212             : /*************************************************************************
     213             : |*
     214             : |* Bitmap einer beliebigen Seite erzeugen
     215             : |*
     216             : \************************************************************************/
     217             : 
     218           0 : Bitmap DrawDocShell::GetPagePreviewBitmap(SdPage* pPage, sal_uInt16 nMaxEdgePixel)
     219             : {
     220           0 :     MapMode         aMapMode( MAP_100TH_MM );
     221           0 :     const Size      aSize( pPage->GetSize() );
     222           0 :     const Point     aNullPt;
     223           0 :     VirtualDevice   aVDev( *Application::GetDefaultDevice() );
     224             : 
     225           0 :     aVDev.SetMapMode( aMapMode );
     226             : 
     227           0 :     const Size  aPixSize( aVDev.LogicToPixel( aSize ) );
     228           0 :     const sal_uLong nMaxEdgePix = Max( aPixSize.Width(), aPixSize.Height() );
     229           0 :     Fraction    aFrac( nMaxEdgePixel, nMaxEdgePix );
     230             : 
     231           0 :     aMapMode.SetScaleX( aFrac );
     232           0 :     aMapMode.SetScaleY( aFrac );
     233           0 :     aVDev.SetMapMode( aMapMode );
     234           0 :     aVDev.SetOutputSize( aSize );
     235             : 
     236             :     // damit die dunklen Linien am rechten und unteren Seitenrans mitkommen
     237           0 :     aFrac = Fraction( nMaxEdgePixel - 1, nMaxEdgePix );
     238           0 :     aMapMode.SetScaleX( aFrac );
     239           0 :     aMapMode.SetScaleY( aFrac );
     240           0 :     aVDev.SetMapMode( aMapMode );
     241             : 
     242           0 :     ClientView* pView = new ClientView( this, &aVDev, NULL );
     243           0 :     FrameView*      pFrameView = GetFrameView();
     244           0 :     pView->ShowSdrPage( pPage );
     245             : 
     246           0 :     if ( GetFrameView() )
     247             :     {
     248             :         // Initialisierungen der Zeichen-(Bildschirm-)Attribute
     249           0 :         pView->SetGridCoarse( pFrameView->GetGridCoarse() );
     250           0 :         pView->SetGridFine( pFrameView->GetGridFine() );
     251           0 :         pView->SetSnapGridWidth(pFrameView->GetSnapGridWidthX(), pFrameView->GetSnapGridWidthY());
     252           0 :         pView->SetGridVisible( pFrameView->IsGridVisible() );
     253           0 :         pView->SetGridFront( pFrameView->IsGridFront() );
     254           0 :         pView->SetSnapAngle( pFrameView->GetSnapAngle() );
     255           0 :         pView->SetGridSnap( pFrameView->IsGridSnap() );
     256           0 :         pView->SetBordSnap( pFrameView->IsBordSnap() );
     257           0 :         pView->SetHlplSnap( pFrameView->IsHlplSnap() );
     258           0 :         pView->SetOFrmSnap( pFrameView->IsOFrmSnap() );
     259           0 :         pView->SetOPntSnap( pFrameView->IsOPntSnap() );
     260           0 :         pView->SetOConSnap( pFrameView->IsOConSnap() );
     261           0 :         pView->SetDragStripes( pFrameView->IsDragStripes() );
     262           0 :         pView->SetFrameDragSingles( pFrameView->IsFrameDragSingles() );
     263           0 :         pView->SetSnapMagneticPixel( pFrameView->GetSnapMagneticPixel() );
     264           0 :         pView->SetMarkedHitMovesAlways( pFrameView->IsMarkedHitMovesAlways() );
     265           0 :         pView->SetMoveOnlyDragging( pFrameView->IsMoveOnlyDragging() );
     266           0 :         pView->SetSlantButShear( pFrameView->IsSlantButShear() );
     267           0 :         pView->SetNoDragXorPolys( pFrameView->IsNoDragXorPolys() );
     268           0 :         pView->SetCrookNoContortion( pFrameView->IsCrookNoContortion() );
     269           0 :         pView->SetAngleSnapEnabled( pFrameView->IsAngleSnapEnabled() );
     270           0 :         pView->SetBigOrtho( pFrameView->IsBigOrtho() );
     271           0 :         pView->SetOrtho( pFrameView->IsOrtho() );
     272             : 
     273           0 :         SdrPageView* pPageView = pView->GetSdrPageView();
     274             : 
     275           0 :         if (pPageView)
     276             :         {
     277           0 :             if ( pPageView->GetVisibleLayers() != pFrameView->GetVisibleLayers() )
     278           0 :                 pPageView->SetVisibleLayers( pFrameView->GetVisibleLayers() );
     279             : 
     280           0 :             if ( pPageView->GetPrintableLayers() != pFrameView->GetPrintableLayers() )
     281           0 :                 pPageView->SetPrintableLayers( pFrameView->GetPrintableLayers() );
     282             : 
     283           0 :             if ( pPageView->GetLockedLayers() != pFrameView->GetLockedLayers() )
     284           0 :                 pPageView->SetLockedLayers( pFrameView->GetLockedLayers() );
     285             : 
     286           0 :                 pPageView->SetHelpLines( pFrameView->GetStandardHelpLines() );
     287             :         }
     288             : 
     289           0 :         if ( pView->GetActiveLayer() != pFrameView->GetActiveLayer() )
     290           0 :             pView->SetActiveLayer( pFrameView->GetActiveLayer() );
     291             :     }
     292             : 
     293           0 :     pView->CompleteRedraw( &aVDev, Rectangle( aNullPt, aSize ) );
     294             : 
     295             :     // IsRedrawReady() always gives sal_True while ( !pView->IsRedrawReady() ) {}
     296           0 :     delete pView;
     297             : 
     298           0 :     aVDev.SetMapMode( MapMode() );
     299             : 
     300           0 :     Bitmap aPreview( aVDev.GetBitmap( aNullPt, aVDev.GetOutputSizePixel() ) );
     301             : 
     302             :     DBG_ASSERT(!!aPreview, "Vorschau-Bitmap konnte nicht erzeugt werden");
     303             : 
     304           0 :     return aPreview;
     305             : }
     306             : 
     307             : 
     308             : /*************************************************************************
     309             : |*
     310             : |* Pruefen, ob die Seite vorhanden ist und dann den Anwender zwingen einen
     311             : |* noch nicht vorhandenen Namen einzugeben. Wird sal_False zurueckgegeben,
     312             : |* wurde die Aktion vom Anwender abgebrochen.
     313             : |*
     314             : \************************************************************************/
     315             : 
     316           0 : sal_Bool DrawDocShell::CheckPageName (::Window* pWin, String& rName )
     317             : {
     318           0 :     const String aStrForDlg( rName );
     319           0 :     bool bIsNameValid = IsNewPageNameValid( rName, true );
     320             : 
     321           0 :     if( ! bIsNameValid )
     322             :     {
     323           0 :         String aDesc( SdResId( STR_WARN_PAGE_EXISTS ) );
     324           0 :         SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     325           0 :         AbstractSvxNameDialog* aNameDlg = pFact ? pFact->CreateSvxNameDialog( pWin, aStrForDlg, aDesc ) : 0;
     326           0 :         if( aNameDlg )
     327             :         {
     328           0 :             aNameDlg->SetEditHelpId( HID_SD_NAMEDIALOG_PAGE );
     329             : 
     330           0 :             if( mpViewShell )
     331           0 :                 aNameDlg->SetCheckNameHdl( LINK( this, DrawDocShell, RenameSlideHdl ) );
     332             : 
     333           0 :             FunctionReference xFunc( mpViewShell->GetCurrentFunction() );
     334           0 :             if( xFunc.is() )
     335           0 :                 xFunc->cancel();
     336             : 
     337           0 :             if( aNameDlg->Execute() == RET_OK )
     338             :             {
     339           0 :                 aNameDlg->GetName( rName );
     340           0 :                 bIsNameValid = IsNewPageNameValid( rName );
     341             :             }
     342           0 :             delete aNameDlg;
     343           0 :         }
     344             :     }
     345             : 
     346           0 :     return ( bIsNameValid ? sal_True : sal_False );
     347             : }
     348             : 
     349           0 : bool DrawDocShell::IsNewPageNameValid( String & rInOutPageName, bool bResetStringIfStandardName /* = false */ )
     350             : {
     351           0 :     bool bCanUseNewName = false;
     352             : 
     353             :     // check if name is something like 'Slide n'
     354           0 :     String aStrPage( SdResId( STR_SD_PAGE ) );
     355           0 :     aStrPage += ' ';
     356             : 
     357           0 :     bool bIsStandardName = false;
     358             : 
     359             :     // prevent also _future_ slide names of the form "'STR_SD_PAGE' + ' ' + '[0-9]+|[a-z]|[A-Z]|[CDILMVX]+|[cdilmvx]+'"
     360             :     // (arabic, lower- and upper case single letter, lower- and upper case roman numbers)
     361           0 :     if( 0 == rInOutPageName.Search( aStrPage ) )
     362             :     {
     363           0 :         if( rInOutPageName.GetToken( 1, sal_Unicode(' ') ).GetChar(0) >= '0' &&
     364           0 :             rInOutPageName.GetToken( 1, sal_Unicode(' ') ).GetChar(0) <= '9' )
     365             :         {
     366             :             // check for arabic numbering
     367             : 
     368             :             // gobble up all following numbers
     369           0 :             String sRemainder = rInOutPageName.GetToken( 1, sal_Unicode(' ') );
     370           0 :             while( sRemainder.Len() &&
     371           0 :                    sRemainder.GetChar(0) >= '0' &&
     372           0 :                    sRemainder.GetChar(0) <= '9' )
     373             :             {
     374             :                 // trim by one
     375           0 :                 sRemainder.Erase(0, 1);
     376             :             }
     377             : 
     378             :             // EOL? Reserved name!
     379           0 :             if( !sRemainder.Len() )
     380             :             {
     381           0 :                 bIsStandardName = true;
     382           0 :             }
     383             :         }
     384           0 :         else if( rInOutPageName.GetToken( 1, sal_Unicode(' ') ).Len() == 1 &&
     385           0 :                  comphelper::string::islowerAscii(rInOutPageName.GetToken( 1, sal_Unicode(' ') ).GetChar(0) ) )
     386             :         {
     387             :             // lower case, single character: reserved
     388           0 :             bIsStandardName = true;
     389             :         }
     390           0 :         else if( rInOutPageName.GetToken( 1, sal_Unicode(' ') ).Len() == 1 &&
     391           0 :                  comphelper::string::isupperAscii(rInOutPageName.GetToken( 1, sal_Unicode(' ') ).GetChar(0) ) )
     392             :         {
     393             :             // upper case, single character: reserved
     394           0 :             bIsStandardName = true;
     395             :         }
     396             :         else
     397             :         {
     398             :             // check for upper/lower case roman numbering
     399           0 :             String sReserved( rtl::OUString("cdilmvx") );
     400             : 
     401             :             // gobble up all following characters contained in one reserved class
     402           0 :             String sRemainder = rInOutPageName.GetToken( 1, sal_Unicode(' ') );
     403           0 :             if( sReserved.Search( sRemainder.GetChar(0) ) == STRING_NOTFOUND )
     404           0 :                 sReserved.ToUpperAscii();
     405             : 
     406           0 :             while( sReserved.Search( sRemainder.GetChar(0) ) != STRING_NOTFOUND )
     407             :             {
     408             :                 // trim by one
     409           0 :                 sRemainder.Erase(0, 1);
     410             :             }
     411             : 
     412             :             // EOL? Reserved name!
     413           0 :             if( !sRemainder.Len() )
     414             :             {
     415           0 :                 bIsStandardName = true;
     416           0 :             }
     417             :         }
     418             :     }
     419             : 
     420           0 :     if( bIsStandardName )
     421             :     {
     422           0 :         if( bResetStringIfStandardName )
     423             :         {
     424             :             // this is for insertion of slides from other files with standard
     425             :             // name.  They get a new standard name, if the string is set to an
     426             :             // empty one.
     427           0 :             rInOutPageName = String();
     428           0 :             bCanUseNewName = true;
     429             :         }
     430             :         else
     431           0 :             bCanUseNewName = false;
     432             :     }
     433             :     else
     434             :     {
     435           0 :         if( rInOutPageName.Len() > 0 )
     436             :         {
     437             :             sal_Bool   bOutDummy;
     438           0 :             sal_uInt16 nExistingPageNum = mpDoc->GetPageByName( rInOutPageName, bOutDummy );
     439           0 :             bCanUseNewName = ( nExistingPageNum == SDRPAGE_NOTFOUND );
     440             :         }
     441             :         else
     442           0 :             bCanUseNewName = false;
     443             :     }
     444             : 
     445           0 :     return bCanUseNewName;
     446             : }
     447             : 
     448           0 : IMPL_LINK( DrawDocShell, RenameSlideHdl, AbstractSvxNameDialog*, pDialog )
     449             : {
     450           0 :     if( ! pDialog )
     451           0 :         return 0;
     452             : 
     453           0 :     String aNewName;
     454           0 :     pDialog->GetName( aNewName );
     455             : 
     456           0 :     return IsNewPageNameValid( aNewName );
     457             : }
     458          18 : } // end of namespace sd
     459             : 
     460             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10