1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <view/SlsInsertionIndicatorOverlay.hxx>
#include <SlideSorter.hxx>
#include <view/SlideSorterView.hxx>
#include <view/SlsLayouter.hxx>
#include <view/SlsPageObjectLayouter.hxx>
#include <view/SlsTheme.hxx>
#include "SlsFramePainter.hxx"
#include "SlsLayeredDevice.hxx"
#include <DrawDocShell.hxx>
#include <drawdoc.hxx>
#include <Window.hxx>
#include <vcl/virdev.hxx>
#include <basegfx/range/b2drectangle.hxx>
#include <basegfx/polygon/b2dpolygon.hxx>
#include <basegfx/polygon/b2dpolygontools.hxx>
namespace {
static const double gnPreviewOffsetScale = 1.0 / 8.0;
::tools::Rectangle GrowRectangle (const ::tools::Rectangle& rBox, const sal_Int32 nOffset)
{
return ::tools::Rectangle (
rBox.Left() - nOffset,
rBox.Top() - nOffset,
rBox.Right() + nOffset,
rBox.Bottom() + nOffset);
}
sal_Int32 RoundToInt (const double nValue) { return sal_Int32(::rtl::math::round(nValue)); }
} // end of anonymous namespace
namespace sd::slidesorter::view {
//===== InsertionIndicatorOverlay ===========================================
const static sal_Int32 gnShadowBorder = 3;
const static sal_Int32 gnLayerIndex = 2;
InsertionIndicatorOverlay::InsertionIndicatorOverlay (SlideSorter& rSlideSorter)
: mrSlideSorter(rSlideSorter),
mbIsVisible(false),
mpLayerInvalidator(),
maLocation(),
maIcon(),
mpShadowPainter(
new FramePainter(mrSlideSorter.GetTheme()->GetIcon(Theme::Icon_RawInsertShadow)))
{
}
InsertionIndicatorOverlay::~InsertionIndicatorOverlay() COVERITY_NOEXCEPT_FALSE
{
Hide();
}
void InsertionIndicatorOverlay::Create (const SdTransferable* pTransferable)
{
if (pTransferable == nullptr)
return;
std::shared_ptr<controller::TransferableData> pData (
controller::TransferableData::GetFromTransferable(pTransferable));
if ( ! pData)
return;
sal_Int32 nSelectionCount (0);
if (pTransferable->HasPageBookmarks())
nSelectionCount = pTransferable->GetPageBookmarks().size();
else
{
DrawDocShell* pDataDocShell = dynamic_cast<DrawDocShell*>(pTransferable->GetDocShell().get());
if (pDataDocShell != nullptr)
{
SdDrawDocument* pDataDocument = pDataDocShell->GetDoc();
if (pDataDocument != nullptr)
nSelectionCount = pDataDocument->GetSdPageCount(PageKind::Standard);
}
}
Create(pData->GetRepresentatives(), nSelectionCount);
}
void InsertionIndicatorOverlay::Create (
const ::std::vector<controller::TransferableData::Representative>& rRepresentatives,
const sal_Int32 nSelectionCount)
{
view::Layouter& rLayouter (mrSlideSorter.GetView().GetLayouter());
const std::shared_ptr<view::PageObjectLayouter>& pPageObjectLayouter (
rLayouter.GetPageObjectLayouter());
std::shared_ptr<view::Theme> pTheme (mrSlideSorter.GetTheme());
const Size aOriginalPreviewSize (pPageObjectLayouter->GetPreviewSize());
const double nPreviewScale (0.5);
const Size aPreviewSize (
RoundToInt(aOriginalPreviewSize.Width()*nPreviewScale),
RoundToInt(aOriginalPreviewSize.Height()*nPreviewScale));
const sal_Int32 nOffset (
RoundToInt(std::min(aPreviewSize.Width(),aPreviewSize.Height()) * gnPreviewOffsetScale));
// Determine size and offset depending on the number of previews.
sal_Int32 nCount (rRepresentatives.size());
if (nCount > 0)
--nCount;
Size aIconSize(
aPreviewSize.Width() + 2 * gnShadowBorder + nCount*nOffset,
aPreviewSize.Height() + 2 * gnShadowBorder + nCount*nOffset);
// Create virtual devices for bitmap and mask whose bitmaps later be
// combined to form the BitmapEx of the icon.
ScopedVclPtrInstance<VirtualDevice> pContent(
*mrSlideSorter.GetContentWindow(), DeviceFormat::DEFAULT, DeviceFormat::DEFAULT);
pContent->SetOutputSizePixel(aIconSize);
pContent->SetFillColor();
pContent->SetLineColor(pTheme->GetColor(Theme::Color_PreviewBorder));
const Point aOffset = PaintRepresentatives(*pContent, aPreviewSize, nOffset, rRepresentatives);
PaintPageCount(*pContent, nSelectionCount, aPreviewSize, aOffset);
maIcon = pContent->GetBitmapEx(Point(0,0), aIconSize);
maIcon.Scale(aIconSize);
}
Point InsertionIndicatorOverlay::PaintRepresentatives (
OutputDevice& rContent,
const Size& rPreviewSize,
const sal_Int32 nOffset,
const ::std::vector<controller::TransferableData::Representative>& rRepresentatives) const
{
const Point aOffset (0,rRepresentatives.size()==1 ? -nOffset : 0);
// Paint the pages.
Point aPageOffset (0,0);
double nTransparency (0);
const BitmapEx aExclusionOverlay (mrSlideSorter.GetTheme()->GetIcon(Theme::Icon_HideSlideOverlay));
for (sal_Int32 nIndex=2; nIndex>=0; --nIndex)
{
if (rRepresentatives.size() <= sal_uInt32(nIndex))
continue;
switch(nIndex)
{
case 0 :
aPageOffset = Point(0, nOffset);
nTransparency = 0.85;
break;
case 1:
aPageOffset = Point(nOffset, 0);
nTransparency = 0.75;
break;
case 2:
aPageOffset = Point(2*nOffset, 2*nOffset);
nTransparency = 0.65;
break;
}
aPageOffset += aOffset;
aPageOffset.AdjustX(gnShadowBorder );
aPageOffset.AdjustY(gnShadowBorder );
// Paint the preview.
BitmapEx aPreview (rRepresentatives[nIndex].maBitmap);
aPreview.Scale(rPreviewSize, BmpScaleFlag::BestQuality);
rContent.DrawBitmapEx(aPageOffset, aPreview);
// When the page is marked as excluded from the slide show then
// paint an overlay that visualizes this.
if (rRepresentatives[nIndex].mbIsExcluded)
{
const vcl::Region aSavedClipRegion (rContent.GetClipRegion());
rContent.IntersectClipRegion(::tools::Rectangle(aPageOffset, rPreviewSize));
// Paint bitmap tiled over the preview to mark it as excluded.
const sal_Int32 nIconWidth (aExclusionOverlay.GetSizePixel().Width());
const sal_Int32 nIconHeight (aExclusionOverlay.GetSizePixel().Height());
if (nIconWidth>0 && nIconHeight>0)
{
for (long nX=0; nX<rPreviewSize.Width(); nX+=nIconWidth)
for (long nY=0; nY<rPreviewSize.Height(); nY+=nIconHeight)
rContent.DrawBitmapEx(Point(nX,nY)+aPageOffset, aExclusionOverlay);
}
rContent.SetClipRegion(aSavedClipRegion);
}
// Tone down the bitmap. The further back the darker it becomes.
::tools::Rectangle aBox (
aPageOffset.X(),
aPageOffset.Y(),
aPageOffset.X()+rPreviewSize.Width()-1,
aPageOffset.Y()+rPreviewSize.Height()-1);
rContent.SetFillColor(COL_BLACK);
rContent.SetLineColor();
rContent.DrawTransparent(
basegfx::B2DHomMatrix(),
::basegfx::B2DPolyPolygon(::basegfx::utils::createPolygonFromRect(
::basegfx::B2DRectangle(aBox.Left(), aBox.Top(), aBox.Right()+1, aBox.Bottom()+1),
0,
0)),
nTransparency);
// Draw border around preview.
::tools::Rectangle aBorderBox (GrowRectangle(aBox, 1));
rContent.SetLineColor(COL_GRAY);
rContent.SetFillColor();
rContent.DrawRect(aBorderBox);
// Draw shadow around preview.
mpShadowPainter->PaintFrame(rContent, aBorderBox);
}
return aPageOffset;
}
void InsertionIndicatorOverlay::PaintPageCount (
OutputDevice& rDevice,
const sal_Int32 nSelectionCount,
const Size& rPreviewSize,
const Point& rFirstPageOffset) const
{
// Paint the number of slides.
std::shared_ptr<view::Theme> pTheme (mrSlideSorter.GetTheme());
std::shared_ptr<vcl::Font> pFont(Theme::GetFont(Theme::Font_PageCount, rDevice));
if (!pFont)
return;
OUString sNumber (OUString::number(nSelectionCount));
// Determine the size of the (painted) text and create a bounding
// box that centers the text on the first preview.
rDevice.SetFont(*pFont);
::tools::Rectangle aTextBox;
rDevice.GetTextBoundRect(aTextBox, sNumber);
Point aTextOffset (aTextBox.TopLeft());
Size aTextSize (aTextBox.GetSize());
// Place text inside the first page preview.
Point aTextLocation(rFirstPageOffset);
// Center the text.
aTextLocation += Point(
(rPreviewSize.Width()-aTextBox.GetWidth())/2,
(rPreviewSize.Height()-aTextBox.GetHeight())/2);
aTextBox = ::tools::Rectangle(aTextLocation, aTextSize);
// Paint background, border and text.
static const sal_Int32 nBorder = 5;
rDevice.SetFillColor(pTheme->GetColor(Theme::Color_Selection));
rDevice.SetLineColor(pTheme->GetColor(Theme::Color_Selection));
rDevice.DrawRect(GrowRectangle(aTextBox, nBorder));
rDevice.SetFillColor();
rDevice.SetLineColor(pTheme->GetColor(Theme::Color_PageCountFontColor));
rDevice.DrawRect(GrowRectangle(aTextBox, nBorder-1));
rDevice.SetTextColor(pTheme->GetColor(Theme::Color_PageCountFontColor));
rDevice.DrawText(aTextBox.TopLeft()-aTextOffset, sNumber);
}
void InsertionIndicatorOverlay::SetLocation (const Point& rLocation)
{
const Point aTopLeft (
rLocation - Point(
maIcon.GetSizePixel().Width()/2,
maIcon.GetSizePixel().Height()/2));
if (maLocation != aTopLeft)
{
const ::tools::Rectangle aOldBoundingBox (GetBoundingBox());
maLocation = aTopLeft;
if (mpLayerInvalidator && IsVisible())
{
mpLayerInvalidator->Invalidate(aOldBoundingBox);
mpLayerInvalidator->Invalidate(GetBoundingBox());
}
}
}
void InsertionIndicatorOverlay::Paint (
OutputDevice& rDevice,
const ::tools::Rectangle&)
{
if ( ! IsVisible())
return;
rDevice.DrawImage(maLocation, Image(maIcon));
}
void InsertionIndicatorOverlay::SetLayerInvalidator (const SharedILayerInvalidator& rpInvalidator)
{
mpLayerInvalidator = rpInvalidator;
if (mbIsVisible && mpLayerInvalidator)
mpLayerInvalidator->Invalidate(GetBoundingBox());
}
void InsertionIndicatorOverlay::Show()
{
if ( mbIsVisible)
return;
mbIsVisible = true;
std::shared_ptr<LayeredDevice> pLayeredDevice (
mrSlideSorter.GetView().GetLayeredDevice());
if (pLayeredDevice)
{
pLayeredDevice->RegisterPainter(shared_from_this(), gnLayerIndex);
if (mpLayerInvalidator)
mpLayerInvalidator->Invalidate(GetBoundingBox());
}
}
void InsertionIndicatorOverlay::Hide()
{
if (!mbIsVisible)
return;
mbIsVisible = false;
std::shared_ptr<LayeredDevice> pLayeredDevice (
mrSlideSorter.GetView().GetLayeredDevice());
if (pLayeredDevice)
{
if (mpLayerInvalidator)
mpLayerInvalidator->Invalidate(GetBoundingBox());
pLayeredDevice->RemovePainter(shared_from_this(), gnLayerIndex);
}
}
::tools::Rectangle InsertionIndicatorOverlay::GetBoundingBox() const
{
return ::tools::Rectangle(maLocation, maIcon.GetSizePixel());
}
Size InsertionIndicatorOverlay::GetSize() const
{
return Size(
maIcon.GetSizePixel().Width() + 10,
maIcon.GetSizePixel().Height() + 10);
}
} // end of namespace ::sd::slidesorter::view
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|