LibreOffice Module sd (master) 1
docshel2.cxx
Go to the documentation of this file.
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 <memory>
21#include <DrawDocShell.hxx>
22#include <svx/svdpagv.hxx>
23#include <svx/svxdlg.hxx>
24#include <o3tl/string_view.hxx>
25
26#include <helpids.h>
27#include <ViewShell.hxx>
28#include <FrameView.hxx>
29#include <drawdoc.hxx>
30#include <sdpage.hxx>
31#include <ClientView.hxx>
32#include <Window.hxx>
33#include <strings.hrc>
34
35#include <sdresid.hxx>
36#include <fupoor.hxx>
37#include <vcl/svapp.hxx>
38#include <vcl/virdev.hxx>
39#include <rtl/character.hxx>
40#include <tools/debug.hxx>
41
42namespace sd {
43
47void DrawDocShell::Draw(OutputDevice* pOut, const JobSetup&, sal_uInt16 nAspect, bool /*bOutputForScreen*/)
48{
49 if (nAspect == ASPECT_THUMBNAIL)
50 {
51 // THUMBNAIL: here we may can set the draft mode
52 }
53
54 std::optional<ClientView> pView( std::in_place, this, pOut );
55
56 pView->SetHlplVisible(false);
57 pView->SetGridVisible(false);
58 pView->SetBordVisible(false);
59 pView->SetPageVisible(false);
60 pView->SetGlueVisible(false);
61
62 SdPage* pSelectedPage = nullptr;
63
64 const std::vector<std::unique_ptr<sd::FrameView>> &rViews = mpDoc->GetFrameViewList();
65 if( !rViews.empty() )
66 {
67 sd::FrameView* pFrameView = rViews[0].get();
68 if( pFrameView->GetPageKind() == PageKind::Standard )
69 {
70 sal_uInt16 nSelectedPage = pFrameView->GetSelectedPage();
71 pSelectedPage = mpDoc->GetSdPage(nSelectedPage, PageKind::Standard);
72 }
73 }
74
75 if( nullptr == pSelectedPage )
76 {
77 SdPage* pPage = nullptr;
78 sal_uInt16 nPageCnt = mpDoc->GetSdPageCount(PageKind::Standard);
79
80 for (sal_uInt16 i = 0; i < nPageCnt; i++)
81 {
83
84 if ( pPage->IsSelected() )
85 pSelectedPage = pPage;
86 }
87
88 if( nullptr == pSelectedPage )
89 pSelectedPage = mpDoc->GetSdPage(0, PageKind::Standard);
90 }
91
92 ::tools::Rectangle aVisArea = GetVisArea(nAspect);
93 pOut->IntersectClipRegion(aVisArea);
94 pView->ShowSdrPage(pSelectedPage);
95
96 if (pOut->GetOutDevType() == OUTDEV_WINDOW)
97 return;
98
99 MapMode aOldMapMode = pOut->GetMapMode();
100
101 if (pOut->GetOutDevType() == OUTDEV_PRINTER)
102 {
103 MapMode aMapMode = aOldMapMode;
104 Point aOrigin = aMapMode.GetOrigin();
105 aOrigin.AdjustX(1 );
106 aOrigin.AdjustY(1 );
107 aMapMode.SetOrigin(aOrigin);
108 pOut->SetMapMode(aMapMode);
109 }
110
111 vcl::Region aRegion(aVisArea);
112 pView->CompleteRedraw(pOut, aRegion);
113
114 if (pOut->GetOutDevType() == OUTDEV_PRINTER)
115 {
116 pOut->SetMapMode(aOldMapMode);
117 }
118}
119
121{
122 ::tools::Rectangle aVisArea;
123
124 if( ( ASPECT_THUMBNAIL == nAspect ) || ( ASPECT_DOCPRINT == nAspect ) )
125 {
126 // provide size of first page
128 }
129 else
130 {
131 aVisArea = SfxObjectShell::GetVisArea(nAspect);
132 }
133
134 if (aVisArea.IsEmpty() && mpViewShell)
135 {
137
138 if (pWin)
139 {
140 aVisArea = pWin->PixelToLogic(::tools::Rectangle(Point(0,0), pWin->GetOutputSizePixel()));
141 }
142 }
143
144 return aVisArea;
145}
146
148{
149 mpViewShell = pViewSh;
150}
151
153{
154 if (mpViewShell == pViewSh)
155 {
156 mpViewShell = nullptr;
157 }
158}
159
161{
162 FrameView* pFrameView = nullptr;
163
164 if (mpViewShell)
165 {
166 pFrameView = mpViewShell->GetFrameView();
167 }
168
169 return pFrameView;
170}
171
176{
177 const sal_uInt16 nMaxEdgePixel = 90;
178 MapMode aMapMode( MapUnit::Map100thMM );
179 const Size aSize( pPage->GetSize() );
180 const Point aNullPt;
182
183 pVDev->SetMapMode( aMapMode );
184
185 const Size aPixSize( pVDev->LogicToPixel( aSize ) );
186 const sal_uLong nMaxEdgePix = std::max( aPixSize.Width(), aPixSize.Height() );
187 Fraction aFrac( nMaxEdgePixel, nMaxEdgePix );
188
189 aMapMode.SetScaleX( aFrac );
190 aMapMode.SetScaleY( aFrac );
191 pVDev->SetMapMode( aMapMode );
192 pVDev->SetOutputSize( aSize );
193
194 // that we also get the dark lines at the right and bottom page margin
195 aFrac = Fraction( nMaxEdgePixel - 1, nMaxEdgePix );
196 aMapMode.SetScaleX( aFrac );
197 aMapMode.SetScaleY( aFrac );
198 pVDev->SetMapMode( aMapMode );
199
200 std::optional<ClientView> pView( std::in_place, this, pVDev );
201 FrameView* pFrameView = GetFrameView();
202 pView->ShowSdrPage( pPage );
203
204 if ( GetFrameView() )
205 {
206 // initialize the drawing-(screen) attributes
207 pView->SetGridCoarse( pFrameView->GetGridCoarse() );
208 pView->SetGridFine( pFrameView->GetGridFine() );
209 pView->SetSnapGridWidth(pFrameView->GetSnapGridWidthX(), pFrameView->GetSnapGridWidthY());
210 pView->SetGridVisible( pFrameView->IsGridVisible() );
211 pView->SetGridFront( pFrameView->IsGridFront() );
212 pView->SetSnapAngle( pFrameView->GetSnapAngle() );
213 pView->SetGridSnap( pFrameView->IsGridSnap() );
214 pView->SetBordSnap( pFrameView->IsBordSnap() );
215 pView->SetHlplSnap( pFrameView->IsHlplSnap() );
216 pView->SetOFrmSnap( pFrameView->IsOFrmSnap() );
217 pView->SetOPntSnap( pFrameView->IsOPntSnap() );
218 pView->SetOConSnap( pFrameView->IsOConSnap() );
219 pView->SetDragStripes( pFrameView->IsDragStripes() );
220 pView->SetFrameDragSingles( pFrameView->IsFrameDragSingles() );
221 pView->SetSnapMagneticPixel( pFrameView->GetSnapMagneticPixel() );
222 pView->SetMarkedHitMovesAlways( pFrameView->IsMarkedHitMovesAlways() );
223 pView->SetMoveOnlyDragging( pFrameView->IsMoveOnlyDragging() );
224 pView->SetSlantButShear( pFrameView->IsSlantButShear() );
225 pView->SetNoDragXorPolys( pFrameView->IsNoDragXorPolys() );
226 pView->SetCrookNoContortion( pFrameView->IsCrookNoContortion() );
227 pView->SetAngleSnapEnabled( pFrameView->IsAngleSnapEnabled() );
228 pView->SetBigOrtho( pFrameView->IsBigOrtho() );
229 pView->SetOrtho( pFrameView->IsOrtho() );
230
231 SdrPageView* pPageView = pView->GetSdrPageView();
232
233 if (pPageView)
234 {
235 if ( pPageView->GetVisibleLayers() != pFrameView->GetVisibleLayers() )
236 pPageView->SetVisibleLayers( pFrameView->GetVisibleLayers() );
237
238 if ( pPageView->GetPrintableLayers() != pFrameView->GetPrintableLayers() )
239 pPageView->SetPrintableLayers( pFrameView->GetPrintableLayers() );
240
241 if ( pPageView->GetLockedLayers() != pFrameView->GetLockedLayers() )
242 pPageView->SetLockedLayers( pFrameView->GetLockedLayers() );
243
244 pPageView->SetHelpLines( pFrameView->GetStandardHelpLines() );
245 }
246
247 if ( pView->GetActiveLayer() != pFrameView->GetActiveLayer() )
248 pView->SetActiveLayer( pFrameView->GetActiveLayer() );
249 }
250
251 pView->CompleteRedraw( pVDev, vcl::Region(::tools::Rectangle(aNullPt, aSize)) );
252
253 // IsRedrawReady() always gives sal_True while ( !pView->IsRedrawReady() ) {}
254 pView.reset();
255
256 pVDev->SetMapMode( MapMode() );
257
258 BitmapEx aPreview( pVDev->GetBitmapEx( aNullPt, pVDev->GetOutputSizePixel() ) );
259
260 DBG_ASSERT(!aPreview.IsEmpty(), "Preview-Bitmap could not be generated");
261
262 return aPreview;
263}
264
270bool DrawDocShell::CheckPageName(weld::Window* pWin, OUString& rName)
271{
272 const OUString aStrForDlg( rName );
273 bool bIsNameValid = IsNewPageNameValid( rName, true );
274
275 if( ! bIsNameValid )
276 {
277 OUString aDesc;
279
281 aDesc = SdResId( STR_WARN_PAGE_EXISTS_DRAW );
282 else
283 aDesc = SdResId( STR_WARN_PAGE_EXISTS );
284
285 ScopedVclPtr<AbstractSvxNameDialog> aNameDlg(pFact->CreateSvxNameDialog(pWin, aStrForDlg, aDesc));
286 aNameDlg->SetEditHelpId( HID_SD_NAMEDIALOG_PAGE );
287
288 aNameDlg->SetCheckNameHdl( LINK( this, DrawDocShell, RenameSlideHdl ) );
289
291 if( xFunc.is() )
292 xFunc->cancel();
293
294 if( aNameDlg->Execute() == RET_OK )
295 {
296 aNameDlg->GetName( rName );
297 bIsNameValid = IsNewPageNameValid( rName );
298 }
299 }
300
301 return bIsNameValid;
302}
303
304bool DrawDocShell::IsNewPageNameValid( OUString & rInOutPageName, bool bResetStringIfStandardName /* = false */ )
305{
306 bool bCanUseNewName = false;
307
308 // check if name is something like 'Slide/Page n'
309 OUString aStrPage;
311 aStrPage = SdResId(STR_PAGE_NAME) + " ";
312 else
313 // using the same strings as SdPage::GetName
314 aStrPage = SdResId(STR_PAGE) + " ";
315
316 bool bIsStandardName = false;
317
318 // prevent also _future_ slide names of the form "'STR_PAGE' + ' ' + '[0-9]+|[a-z]|[A-Z]|[CDILMVX]+|[cdilmvx]+'"
319 // (arabic, lower- and upper case single letter, lower- and upper case roman numbers)
320 if (rInOutPageName.startsWith(aStrPage) &&
321 rInOutPageName.getLength() > aStrPage.getLength())
322 {
323 sal_Int32 nIdx{ aStrPage.getLength() };
324 std::u16string_view sRemainder = o3tl::getToken(rInOutPageName, 0, ' ', nIdx);
325 if (!sRemainder.empty() && sRemainder[0] >= '0' && sRemainder[0] <= '9')
326 {
327 // check for arabic numbering
328
329 size_t nIndex = 1;
330 // skip all following numbers
331 while (nIndex < sRemainder.size() &&
332 sRemainder[nIndex] >= '0' && sRemainder[nIndex] <= '9')
333 {
334 nIndex++;
335 }
336
337 // EOL? Reserved name!
338 if (nIndex >= sRemainder.size())
339 {
340 bIsStandardName = true;
341 }
342 }
343 else if (sRemainder.size() == 1 &&
344 rtl::isAsciiLowerCase(sRemainder[0]))
345 {
346 // lower case, single character: reserved
347 bIsStandardName = true;
348 }
349 else if (sRemainder.size() == 1 &&
350 rtl::isAsciiUpperCase(sRemainder[0]))
351 {
352 // upper case, single character: reserved
353 bIsStandardName = true;
354 }
355 else
356 {
357 // check for upper/lower case roman numbering
358 OUString sReserved("cdilmvx");
359
360 // skip all following characters contained in one reserved class
361 if (sReserved.indexOf(sRemainder[0]) == -1)
362 sReserved = sReserved.toAsciiUpperCase();
363
364 size_t nIndex = 0;
365 while (nIndex < sRemainder.size() &&
366 sReserved.indexOf(sRemainder[nIndex]) != -1)
367 {
368 nIndex++;
369 }
370
371 // EOL? Reserved name!
372 if (nIndex >= sRemainder.size())
373 {
374 bIsStandardName = true;
375 }
376 }
377 }
378
379 if( bIsStandardName )
380 {
381 if( bResetStringIfStandardName )
382 {
383 // this is for insertion of slides from other files with standard
384 // name. They get a new standard name, if the string is set to an
385 // empty one.
386 rInOutPageName.clear();
387 bCanUseNewName = true;
388 }
389 else
390 bCanUseNewName = false;
391 }
392 else
393 {
394 if (!rInOutPageName.isEmpty())
395 {
396 bool bOutDummy;
397 sal_uInt16 nExistingPageNum = mpDoc->GetPageByName( rInOutPageName, bOutDummy );
398 bCanUseNewName = ( nExistingPageNum == SDRPAGE_NOTFOUND );
399 }
400 else
401 bCanUseNewName = false;
402 }
403
404 return bCanUseNewName;
405}
406
407bool DrawDocShell::IsPageNameUnique( std::u16string_view rPageName ) const
408{
409 return mpDoc->IsPageNameUnique(rPageName);
410}
411
412IMPL_LINK( DrawDocShell, RenameSlideHdl, AbstractSvxNameDialog&, rDialog, bool )
413{
414 OUString aNewName;
415 rDialog.GetName( aNewName );
416 return IsNewPageNameValid( aNewName );
417}
418
419} // end of namespace sd
420
421/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static OutputDevice * GetDefaultDevice()
bool IsEmpty() const
void SetOrigin(const Point &rOrigin)
void SetScaleY(const Fraction &rScaleY)
const Point & GetOrigin() const
void SetScaleX(const Fraction &rScaleX)
tools::Long AdjustY(tools::Long nVertMove)
tools::Long AdjustX(tools::Long nHorzMove)
bool IsPageNameUnique(std::u16string_view rPageName) const
checks, if the given name is a unique name for an existing slide
Definition: drawdoc2.cxx:173
SAL_DLLPRIVATE std::vector< std::unique_ptr< sd::FrameView > > & GetFrameViewList()
Definition: drawdoc.hxx:442
SdPage * GetSdPage(sal_uInt16 nPgNum, PageKind ePgKind) const
Definition: drawdoc2.cxx:207
SAL_DLLPRIVATE sal_uInt16 GetPageByName(std::u16string_view rPgName, bool &rbIsMasterPage) const
Return the first page that has the given name.
Definition: drawdoc2.cxx:126
sal_uInt16 GetSdPageCount(PageKind ePgKind) const
Definition: drawdoc2.cxx:212
bool IsSelected() const
Definition: sdpage.hxx:208
bool IsNoDragXorPolys() const
bool IsDragStripes() const
bool IsMarkedHitMovesAlways() const
bool IsFrameDragSingles() const
const SdrLayerIDSet & GetVisibleLayers() const
void SetLockedLayers(const SdrLayerIDSet &rSet)
void SetVisibleLayers(const SdrLayerIDSet &rSet)
void SetPrintableLayers(const SdrLayerIDSet &rSet)
const SdrLayerIDSet & GetLockedLayers() const
const SdrLayerIDSet & GetPrintableLayers() const
void SetHelpLines(const SdrHelpLineList &rHLL)
Size GetSize() const
bool IsGridFront() const
const Size & GetGridFine() const
const Size & GetGridCoarse() const
const OUString & GetActiveLayer() const
bool IsGridVisible() const
bool IsCrookNoContortion() const
bool IsBigOrtho() const
bool IsOrtho() const
const Fraction & GetSnapGridWidthY() const
bool IsHlplSnap() const
bool IsAngleSnapEnabled() const
bool IsOFrmSnap() const
Degree100 GetSnapAngle() const
bool IsGridSnap() const
bool IsOPntSnap() const
bool IsMoveOnlyDragging() const
bool IsOConSnap() const
const Fraction & GetSnapGridWidthX() const
bool IsBordSnap() const
sal_uInt16 GetSnapMagneticPixel() const
bool IsSlantButShear() const
const tools::Rectangle & GetVisArea() const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
virtual VclPtr< AbstractSvxNameDialog > CreateSvxNameDialog(weld::Window *pParent, const OUString &rName, const OUString &rDesc)=0
static SvxAbstractDialogFactory * Create()
bool IsPageNameUnique(std::u16string_view rPagName) const
checks, if the given name is a unique name for an existing slide
Definition: docshel2.cxx:407
::sd::FrameView * GetFrameView()
Definition: docshel2.cxx:160
bool IsNewPageNameValid(OUString &rInOutPageName, bool bResetStringIfStandardName=false)
checks, if the given name is a valid new name for a slide
Definition: docshel2.cxx:304
bool CheckPageName(weld::Window *pWin, OUString &rName)
checks, if the given name is a valid new name for a slide
Definition: docshel2.cxx:270
void Connect(sd::ViewShell *pViewSh)
Definition: docshel2.cxx:147
::sd::ViewShell * mpViewShell
DocumentType GetDocumentType() const
virtual void Draw(OutputDevice *, const JobSetup &rSetup, sal_uInt16 nAspect, bool bOutputForScreen) override
Drawing of DocShell (with the helper class SdDrawViewShell)
Definition: docshel2.cxx:47
BitmapEx GetPagePreviewBitmap(SdPage *pPage)
Creates a bitmap of an arbitrary page.
Definition: docshel2.cxx:175
void Disconnect(sd::ViewShell const *pViewSh)
Definition: docshel2.cxx:152
const tools::Rectangle & GetVisArea() const
SdDrawDocument * mpDoc
SdDrawDocument * GetDoc()
View for MDIFrame.
Definition: FrameView.hxx:36
sal_uInt16 GetSelectedPage() const
Definition: FrameView.hxx:96
const SdrHelpLineList & GetStandardHelpLines() const
Definition: FrameView.hxx:49
const SdrLayerIDSet & GetLockedLayers() const
Definition: FrameView.hxx:63
const SdrLayerIDSet & GetVisibleLayers() const
Definition: FrameView.hxx:59
PageKind GetPageKind() const
Definition: FrameView.hxx:86
const SdrLayerIDSet & GetPrintableLayers() const
Definition: FrameView.hxx:67
Base class of the stacked shell hierarchy.
Definition: ViewShell.hxx:92
const rtl::Reference< FuPoor > & GetCurrentFunction() const
Definition: ViewShell.hxx:250
FrameView * GetFrameView()
Definition: ViewShell.hxx:221
::sd::Window * GetActiveWindow() const
The active window is usually the mpContentWindow.
Definition: ViewShell.hxx:155
void SetSize(const Size &)
constexpr bool IsEmpty() const
Point PixelToLogic(const Point &rDevicePt) const
Size GetOutputSizePixel() const
#define DBG_ASSERT(sCon, aError)
constexpr OUStringLiteral HID_SD_NAMEDIALOG_PAGE
Definition: helpids.h:41
sal_Int32 nIndex
int i
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
IMPL_LINK(SdCharHeightPropertyBox, implMenuSelectHdl, const OUString &, rIdent, void)
#define ASPECT_DOCPRINT
#define ASPECT_THUMBNAIL
OUTDEV_WINDOW
OUTDEV_PRINTER
OUString SdResId(TranslateId aId)
Definition: sdmod.cxx:83
sal_uIntPtr sal_uLong
#define SDRPAGE_NOTFOUND
RET_OK
oslFileHandle & pOut