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