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 :
10 : #include <sfx2/recentdocsviewitem.hxx>
11 :
12 : #include <i18nutil/paper.hxx>
13 : #include <sfx2/templateabstractview.hxx>
14 : #include <sfx2/recentdocsview.hxx>
15 : #include <tools/urlobj.hxx>
16 :
17 0 : RecentDocsViewItem::RecentDocsViewItem(ThumbnailView &rView, const OUString &rURL,
18 : const OUString &rTitle, const BitmapEx &rThumbnail, sal_uInt16 nId)
19 : : ThumbnailViewItem(rView, nId),
20 0 : maURL(rURL)
21 : {
22 0 : OUString aTitle(rTitle);
23 0 : INetURLObject aURLObj(rURL);
24 :
25 0 : if( aURLObj.GetProtocol() == INET_PROT_FILE )
26 0 : m_sHelpText = aURLObj.getFSysPath(INetURLObject::FSYS_DETECT);
27 0 : if( m_sHelpText.isEmpty() )
28 0 : m_sHelpText = aURLObj.GetURLNoPass();
29 :
30 0 : RecentDocsView& rRecentView = dynamic_cast<RecentDocsView&>(rView);
31 0 : long nThumbnailSize = rRecentView.GetThumbnailSize();
32 :
33 0 : if (aTitle.isEmpty())
34 0 : aTitle = aURLObj.GetName(INetURLObject::DECODE_WITH_CHARSET);
35 :
36 0 : BitmapEx aThumbnail(rThumbnail);
37 0 : if (aThumbnail.IsEmpty() && aURLObj.GetProtocol() == INET_PROT_FILE)
38 0 : aThumbnail = ThumbnailView::readThumbnail(rURL);
39 :
40 0 : if (aThumbnail.IsEmpty())
41 : {
42 : // Use the default thumbnail if we have nothing else
43 0 : BitmapEx aExt(RecentDocsView::getDefaultThumbnail(rURL));
44 0 : Size aExtSize(aExt.GetSizePixel());
45 :
46 : // attempt to make it appear as if it is on a piece of paper
47 : long nPaperHeight;
48 : long nPaperWidth;
49 0 : if( RecentDocsView::typeMatchesExtension(TYPE_IMPRESS, aURLObj.getExtension()) )
50 : {
51 : // Swap width and height (PAPER_SCREEN_4_3 definition make it needed)
52 0 : PaperInfo aInfo(PAPER_SCREEN_4_3);
53 0 : nPaperHeight = aInfo.getWidth();
54 0 : nPaperWidth = aInfo.getHeight();
55 : }
56 : else
57 : {
58 0 : PaperInfo aInfo(PaperInfo::getSystemDefaultPaper());
59 0 : nPaperHeight = aInfo.getHeight();
60 0 : nPaperWidth = aInfo.getWidth();
61 : }
62 0 : double ratio = double(nThumbnailSize) / double(std::max(nPaperHeight, nPaperWidth));
63 0 : Size aThumbnailSize(nPaperWidth * ratio, nPaperHeight * ratio);
64 :
65 0 : if (aExtSize.Width() > aThumbnailSize.Width() || aExtSize.Height() > aThumbnailSize.Height())
66 : {
67 0 : aExt = TemplateAbstractView::scaleImg(aExt, aThumbnailSize.Width(), aThumbnailSize.Height());
68 0 : aExtSize = aExt.GetSizePixel();
69 : }
70 :
71 : // create empty, and copy the default thumbnail in
72 0 : sal_uInt8 nAlpha = 255;
73 0 : aThumbnail = BitmapEx(Bitmap(aThumbnailSize, 24), AlphaMask(aThumbnailSize, &nAlpha));
74 :
75 : aThumbnail.CopyPixel(
76 0 : Rectangle(Point((aThumbnailSize.Width() - aExtSize.Width()) / 2, (aThumbnailSize.Height() - aExtSize.Height()) / 2), aExtSize),
77 : Rectangle(Point(0, 0), aExtSize),
78 0 : &aExt);
79 : }
80 :
81 0 : maTitle = aTitle;
82 0 : maPreview1 = TemplateAbstractView::scaleImg(aThumbnail, nThumbnailSize, nThumbnailSize);
83 0 : }
84 :
85 0 : void RecentDocsViewItem::setEditTitle (bool edit, bool bChangeFocus)
86 : {
87 : // Unused parameters.
88 : (void)edit;
89 : (void)bChangeFocus;
90 0 : }
91 :
92 0 : OUString RecentDocsViewItem::getHelpText() const
93 : {
94 0 : return m_sHelpText;
95 : }
96 :
97 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|