bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / docshell / docshel2.cxx
blobb4e66d5caf4c161fa46f131d6acd09e13a52c8ca
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "DrawDocShell.hxx"
21 #include <vcl/msgbox.hxx>
22 #include <svx/svdpagv.hxx>
23 #include <svx/svxdlg.hxx>
24 #include <svx/dialogs.hrc>
26 #include "helpids.h"
27 #include "ViewShell.hxx"
28 #include "drawview.hxx"
29 #include "FrameView.hxx"
30 #include "drawdoc.hxx"
31 #include "sdpage.hxx"
32 #include "View.hxx"
33 #include "ClientView.hxx"
34 #include "Window.hxx"
35 #include "strings.hrc"
36 #include "res_bmp.hrc"
37 #include "sdresid.hxx"
38 #include "strmname.h"
39 #include "fupoor.hxx"
40 #include <vcl/svapp.hxx>
41 #include <vcl/virdev.hxx>
42 #include <comphelper/string.hxx>
44 namespace sd {
46 /**
47 * Drawing of DocShell (with the helper class SdDrawViewShell)
49 void DrawDocShell::Draw(OutputDevice* pOut, const JobSetup&, sal_uInt16 nAspect)
51 if (nAspect == ASPECT_THUMBNAIL)
53 // THUMBNAIL: here we may can set the draft mode
56 ClientView* pView = new ClientView(this, pOut, NULL);
58 pView->SetHlplVisible(false);
59 pView->SetGridVisible(false);
60 pView->SetBordVisible(false);
61 pView->SetPageVisible(false);
62 pView->SetGlueVisible(false);
64 SdPage* pSelectedPage = NULL;
66 const std::vector<sd::FrameView*> &rViews = mpDoc->GetFrameViewList();
67 if( !rViews.empty() )
69 sd::FrameView* pFrameView = rViews[0];
70 if( pFrameView->GetPageKind() == PK_STANDARD )
72 sal_uInt16 nSelectedPage = pFrameView->GetSelectedPage();
73 pSelectedPage = mpDoc->GetSdPage(nSelectedPage, PK_STANDARD);
77 if( NULL == pSelectedPage )
79 SdPage* pPage = NULL;
80 sal_uInt16 nPageCnt = (sal_uInt16) mpDoc->GetSdPageCount(PK_STANDARD);
82 for (sal_uInt16 i = 0; i < nPageCnt; i++)
84 pPage = mpDoc->GetSdPage(i, PK_STANDARD);
86 if ( pPage->IsSelected() )
87 pSelectedPage = pPage;
90 if( NULL == pSelectedPage )
91 pSelectedPage = mpDoc->GetSdPage(0, PK_STANDARD);
94 Rectangle aVisArea = GetVisArea(nAspect);
95 pOut->IntersectClipRegion(aVisArea);
96 pView->ShowSdrPage(pSelectedPage);
98 if (pOut->GetOutDevType() != OUTDEV_WINDOW)
100 MapMode aOldMapMode = pOut->GetMapMode();
102 if (pOut->GetOutDevType() == OUTDEV_PRINTER)
104 MapMode aMapMode = aOldMapMode;
105 Point aOrigin = aMapMode.GetOrigin();
106 aOrigin.X() += 1;
107 aOrigin.Y() += 1;
108 aMapMode.SetOrigin(aOrigin);
109 pOut->SetMapMode(aMapMode);
112 vcl::Region aRegion(aVisArea);
113 pView->CompleteRedraw(pOut, aRegion);
115 if (pOut->GetOutDevType() == OUTDEV_PRINTER)
117 pOut->SetMapMode(aOldMapMode);
121 delete pView;
125 Rectangle DrawDocShell::GetVisArea(sal_uInt16 nAspect) const
127 Rectangle aVisArea;
129 if( ( ASPECT_THUMBNAIL == nAspect ) || ( ASPECT_DOCPRINT == nAspect ) )
131 // provide size of first page
132 MapMode aSrcMapMode(MAP_PIXEL);
133 MapMode aDstMapMode(MAP_100TH_MM);
134 Size aSize = mpDoc->GetSdPage(0, PK_STANDARD)->GetSize();
135 aSrcMapMode.SetMapUnit(MAP_100TH_MM);
137 aSize = Application::GetDefaultDevice()->LogicToLogic(aSize, &aSrcMapMode, &aDstMapMode);
138 aVisArea.SetSize(aSize);
140 else
142 aVisArea = SfxObjectShell::GetVisArea(nAspect);
145 if (aVisArea.IsEmpty() && mpViewShell)
147 vcl::Window* pWin = mpViewShell->GetActiveWindow();
149 if (pWin)
151 aVisArea = pWin->PixelToLogic(Rectangle(Point(0,0), pWin->GetOutputSizePixel()));
155 return aVisArea;
158 void DrawDocShell::Connect(ViewShell* pViewSh)
160 mpViewShell = pViewSh;
163 void DrawDocShell::Disconnect(ViewShell* pViewSh)
165 if (mpViewShell == pViewSh)
167 mpViewShell = NULL;
171 FrameView* DrawDocShell::GetFrameView()
173 FrameView* pFrameView = NULL;
175 if (mpViewShell)
177 pFrameView = mpViewShell->GetFrameView();
180 return pFrameView;
183 Size DrawDocShell::GetFirstPageSize()
185 return SfxObjectShell::GetFirstPageSize();
189 * Creates a bitmap of an arbitrary page
191 Bitmap DrawDocShell::GetPagePreviewBitmap(SdPage* pPage, sal_uInt16 nMaxEdgePixel)
193 MapMode aMapMode( MAP_100TH_MM );
194 const Size aSize( pPage->GetSize() );
195 const Point aNullPt;
196 ScopedVclPtrInstance< VirtualDevice > pVDev( *Application::GetDefaultDevice() );
198 pVDev->SetMapMode( aMapMode );
200 const Size aPixSize( pVDev->LogicToPixel( aSize ) );
201 const sal_uLong nMaxEdgePix = std::max( aPixSize.Width(), aPixSize.Height() );
202 Fraction aFrac( nMaxEdgePixel, nMaxEdgePix );
204 aMapMode.SetScaleX( aFrac );
205 aMapMode.SetScaleY( aFrac );
206 pVDev->SetMapMode( aMapMode );
207 pVDev->SetOutputSize( aSize );
209 // that we also get the dark lines at the right and bottom page margin
210 aFrac = Fraction( nMaxEdgePixel - 1, nMaxEdgePix );
211 aMapMode.SetScaleX( aFrac );
212 aMapMode.SetScaleY( aFrac );
213 pVDev->SetMapMode( aMapMode );
215 ClientView* pView = new ClientView( this, pVDev, NULL );
216 FrameView* pFrameView = GetFrameView();
217 pView->ShowSdrPage( pPage );
219 if ( GetFrameView() )
221 // initialize the drawing-(screen) attributes
222 pView->SetGridCoarse( pFrameView->GetGridCoarse() );
223 pView->SetGridFine( pFrameView->GetGridFine() );
224 pView->SetSnapGridWidth(pFrameView->GetSnapGridWidthX(), pFrameView->GetSnapGridWidthY());
225 pView->SetGridVisible( pFrameView->IsGridVisible() );
226 pView->SetGridFront( pFrameView->IsGridFront() );
227 pView->SetSnapAngle( pFrameView->GetSnapAngle() );
228 pView->SetGridSnap( pFrameView->IsGridSnap() );
229 pView->SetBordSnap( pFrameView->IsBordSnap() );
230 pView->SetHlplSnap( pFrameView->IsHlplSnap() );
231 pView->SetOFrmSnap( pFrameView->IsOFrmSnap() );
232 pView->SetOPntSnap( pFrameView->IsOPntSnap() );
233 pView->SetOConSnap( pFrameView->IsOConSnap() );
234 pView->SetDragStripes( pFrameView->IsDragStripes() );
235 pView->SetFrameDragSingles( pFrameView->IsFrameDragSingles() );
236 pView->SetSnapMagneticPixel( pFrameView->GetSnapMagneticPixel() );
237 pView->SetMarkedHitMovesAlways( pFrameView->IsMarkedHitMovesAlways() );
238 pView->SetMoveOnlyDragging( pFrameView->IsMoveOnlyDragging() );
239 pView->SetSlantButShear( pFrameView->IsSlantButShear() );
240 pView->SetNoDragXorPolys( pFrameView->IsNoDragXorPolys() );
241 pView->SetCrookNoContortion( pFrameView->IsCrookNoContortion() );
242 pView->SetAngleSnapEnabled( pFrameView->IsAngleSnapEnabled() );
243 pView->SetBigOrtho( pFrameView->IsBigOrtho() );
244 pView->SetOrtho( pFrameView->IsOrtho() );
246 SdrPageView* pPageView = pView->GetSdrPageView();
248 if (pPageView)
250 if ( pPageView->GetVisibleLayers() != pFrameView->GetVisibleLayers() )
251 pPageView->SetVisibleLayers( pFrameView->GetVisibleLayers() );
253 if ( pPageView->GetPrintableLayers() != pFrameView->GetPrintableLayers() )
254 pPageView->SetPrintableLayers( pFrameView->GetPrintableLayers() );
256 if ( pPageView->GetLockedLayers() != pFrameView->GetLockedLayers() )
257 pPageView->SetLockedLayers( pFrameView->GetLockedLayers() );
259 pPageView->SetHelpLines( pFrameView->GetStandardHelpLines() );
262 if ( pView->GetActiveLayer() != pFrameView->GetActiveLayer() )
263 pView->SetActiveLayer( pFrameView->GetActiveLayer() );
266 pView->CompleteRedraw( pVDev, vcl::Region(Rectangle(aNullPt, aSize)) );
268 // IsRedrawReady() always gives sal_True while ( !pView->IsRedrawReady() ) {}
269 delete pView;
271 pVDev->SetMapMode( MapMode() );
273 Bitmap aPreview( pVDev->GetBitmap( aNullPt, pVDev->GetOutputSizePixel() ) );
275 DBG_ASSERT(!!aPreview, "Preview-Bitmap could not be generated");
277 return aPreview;
281 * Checks if the page exists. If so, we force the user to enter a not yet used
282 * name.
283 * @return sal_False if the user cancels the action.
285 bool DrawDocShell::CheckPageName (vcl::Window* pWin, OUString& rName )
287 const OUString aStrForDlg( rName );
288 bool bIsNameValid = IsNewPageNameValid( rName, true );
290 if( ! bIsNameValid )
292 OUString aDesc( SD_RESSTR( STR_WARN_PAGE_EXISTS ) );
293 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
294 AbstractSvxNameDialog* aNameDlg = pFact ? pFact->CreateSvxNameDialog( pWin, aStrForDlg, aDesc ) : 0;
295 if( aNameDlg )
297 aNameDlg->SetEditHelpId( HID_SD_NAMEDIALOG_PAGE );
299 aNameDlg->SetCheckNameHdl( LINK( this, DrawDocShell, RenameSlideHdl ) );
301 rtl::Reference<FuPoor> xFunc( mpViewShell->GetCurrentFunction() );
302 if( xFunc.is() )
303 xFunc->cancel();
305 if( aNameDlg->Execute() == RET_OK )
307 aNameDlg->GetName( rName );
308 bIsNameValid = IsNewPageNameValid( rName );
310 delete aNameDlg;
314 return bIsNameValid;
317 bool DrawDocShell::IsNewPageNameValid( OUString & rInOutPageName, bool bResetStringIfStandardName /* = false */ )
319 bool bCanUseNewName = false;
321 // check if name is something like 'Slide n'
322 OUString aStrPage(SD_RESSTR(STR_SD_PAGE) + " ");
324 bool bIsStandardName = false;
326 // prevent also _future_ slide names of the form "'STR_SD_PAGE' + ' ' + '[0-9]+|[a-z]|[A-Z]|[CDILMVX]+|[cdilmvx]+'"
327 // (arabic, lower- and upper case single letter, lower- and upper case roman numbers)
328 if (rInOutPageName.startsWith(aStrPage) &&
329 rInOutPageName.getLength() > aStrPage.getLength())
331 OUString sRemainder = rInOutPageName.getToken(1, ' ');
332 if (sRemainder[0] >= '0' && sRemainder[0] <= '9')
334 // check for arabic numbering
336 sal_Int32 nIndex = 1;
337 // skip all following numbers
338 while (nIndex < sRemainder.getLength() &&
339 sRemainder[nIndex] >= '0' && sRemainder[nIndex] <= '9')
341 nIndex++;
344 // EOL? Reserved name!
345 if (nIndex >= sRemainder.getLength())
347 bIsStandardName = true;
350 else if (sRemainder.getLength() == 1 &&
351 comphelper::string::islowerAscii(sRemainder[0]))
353 // lower case, single character: reserved
354 bIsStandardName = true;
356 else if (sRemainder.getLength() == 1 &&
357 comphelper::string::isupperAscii(sRemainder[0]))
359 // upper case, single character: reserved
360 bIsStandardName = true;
362 else
364 // check for upper/lower case roman numbering
365 OUString sReserved("cdilmvx");
367 // skip all following characters contained in one reserved class
368 if (sReserved.indexOf(sRemainder[0]) == -1)
369 sReserved = sReserved.toAsciiUpperCase();
371 sal_Int32 nIndex = 0;
372 while (nIndex < sRemainder.getLength() &&
373 sReserved.indexOf(sRemainder[nIndex]) != -1)
375 nIndex++;
378 // EOL? Reserved name!
379 if (nIndex >= sRemainder.getLength())
381 bIsStandardName = true;
386 if( bIsStandardName )
388 if( bResetStringIfStandardName )
390 // this is for insertion of slides from other files with standard
391 // name. They get a new standard name, if the string is set to an
392 // empty one.
393 rInOutPageName.clear();
394 bCanUseNewName = true;
396 else
397 bCanUseNewName = false;
399 else
401 if (!rInOutPageName.isEmpty())
403 bool bOutDummy;
404 sal_uInt16 nExistingPageNum = mpDoc->GetPageByName( rInOutPageName, bOutDummy );
405 bCanUseNewName = ( nExistingPageNum == SDRPAGE_NOTFOUND );
407 else
408 bCanUseNewName = false;
411 return bCanUseNewName;
414 IMPL_LINK( DrawDocShell, RenameSlideHdl, AbstractSvxNameDialog*, pDialog )
416 if( ! pDialog )
417 return long(false);
419 OUString aNewName;
420 pDialog->GetName( aNewName );
422 return long(IsNewPageNameValid( aNewName ));
424 } // end of namespace sd
426 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */