bump product version to 5.0.4.1
[LibreOffice.git] / sfx2 / source / control / recentdocsviewitem.cxx
blob0b202ca8c815ea4a8a6a6990537b70b266d0d137
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/.
8 */
10 #include <sfx2/recentdocsviewitem.hxx>
12 #include <com/sun/star/frame/Desktop.hpp>
13 #include <com/sun/star/util/URLTransformer.hpp>
14 #include <drawinglayer/primitive2d/baseprimitive2d.hxx>
15 #include <drawinglayer/primitive2d/discretebitmapprimitive2d.hxx>
16 #include <drawinglayer/processor2d/baseprocessor2d.hxx>
17 #include <i18nutil/paper.hxx>
18 #include <sfx2/recentdocsview.hxx>
19 #include <sfx2/sfxresid.hxx>
20 #include <sfx2/templateabstractview.hxx>
21 #include <tools/urlobj.hxx>
22 #include <unotools/historyoptions.hxx>
23 #include <vcl/svapp.hxx>
25 #include <templateview.hrc>
27 using namespace basegfx;
28 using namespace com::sun::star;
29 using namespace com::sun::star::uno;
30 using namespace drawinglayer::primitive2d;
31 using namespace drawinglayer::processor2d;
33 RecentDocsViewItem::RecentDocsViewItem(ThumbnailView &rView, const OUString &rURL,
34 const OUString &rTitle, const BitmapEx &rThumbnail, sal_uInt16 nId, long nThumbnailSize)
35 : ThumbnailViewItem(rView, nId),
36 maURL(rURL),
37 m_bRemoveIconHighlighted(false),
38 m_aRemoveRecentBitmap(SfxResId(IMG_RECENTDOC_REMOVE)),
39 m_aRemoveRecentBitmapHighlighted(SfxResId(IMG_RECENTDOC_REMOVE_HIGHLIGHTED))
41 OUString aTitle(rTitle);
42 INetURLObject aURLObj(rURL);
44 if( aURLObj.GetProtocol() == INetProtocol::File )
45 m_sHelpText = aURLObj.getFSysPath(INetURLObject::FSYS_DETECT);
46 if( m_sHelpText.isEmpty() )
47 m_sHelpText = aURLObj.GetURLNoPass();
49 if (aTitle.isEmpty())
50 aTitle = aURLObj.GetName(INetURLObject::DECODE_WITH_CHARSET);
52 BitmapEx aThumbnail(rThumbnail);
53 if (aThumbnail.IsEmpty() && aURLObj.GetProtocol() == INetProtocol::File)
54 aThumbnail = ThumbnailView::readThumbnail(rURL);
56 if (aThumbnail.IsEmpty())
58 // Use the default thumbnail if we have nothing else
59 BitmapEx aExt(RecentDocsView::getDefaultThumbnail(rURL));
60 Size aExtSize(aExt.GetSizePixel());
62 // attempt to make it appear as if it is on a piece of paper
63 long nPaperHeight;
64 long nPaperWidth;
65 if( RecentDocsView::typeMatchesExtension(TYPE_IMPRESS, aURLObj.getExtension()) )
67 // Swap width and height (PAPER_SCREEN_4_3 definition make it needed)
68 PaperInfo aInfo(PAPER_SCREEN_4_3);
69 nPaperHeight = aInfo.getWidth();
70 nPaperWidth = aInfo.getHeight();
72 else
74 PaperInfo aInfo(PaperInfo::getSystemDefaultPaper());
75 nPaperHeight = aInfo.getHeight();
76 nPaperWidth = aInfo.getWidth();
78 double ratio = double(nThumbnailSize) / double(std::max(nPaperHeight, nPaperWidth));
79 Size aThumbnailSize(nPaperWidth * ratio, nPaperHeight * ratio);
81 if (aExtSize.Width() > aThumbnailSize.Width() || aExtSize.Height() > aThumbnailSize.Height())
83 aExt = TemplateAbstractView::scaleImg(aExt, aThumbnailSize.Width(), aThumbnailSize.Height());
84 aExtSize = aExt.GetSizePixel();
87 // create empty, and copy the default thumbnail in
88 sal_uInt8 nAlpha = 255;
89 aThumbnail = BitmapEx(Bitmap(aThumbnailSize, 24), AlphaMask(aThumbnailSize, &nAlpha));
91 aThumbnail.CopyPixel(
92 Rectangle(Point((aThumbnailSize.Width() - aExtSize.Width()) / 2, (aThumbnailSize.Height() - aExtSize.Height()) / 2), aExtSize),
93 Rectangle(Point(0, 0), aExtSize),
94 &aExt);
97 maTitle = aTitle;
98 maPreview1 = TemplateAbstractView::scaleImg(aThumbnail, nThumbnailSize, nThumbnailSize);
101 void RecentDocsViewItem::setEditTitle (bool edit, bool bChangeFocus)
103 // Unused parameters.
104 (void)edit;
105 (void)bChangeFocus;
108 Rectangle RecentDocsViewItem::updateHighlight(bool bVisible, const Point& rPoint)
110 Rectangle aRect(ThumbnailViewItem::updateHighlight(bVisible, rPoint));
112 if (bVisible && getRemoveIconArea().IsInside(rPoint))
114 if (!m_bRemoveIconHighlighted)
115 aRect.Union(getRemoveIconArea());
117 m_bRemoveIconHighlighted = true;
119 else
121 if (m_bRemoveIconHighlighted)
122 aRect.Union(getRemoveIconArea());
124 m_bRemoveIconHighlighted = false;
127 return aRect;
130 Rectangle RecentDocsViewItem::getRemoveIconArea() const
132 Rectangle aArea(getDrawArea());
133 Size aSize(m_aRemoveRecentBitmap.GetSizePixel());
135 return Rectangle(
136 Point(aArea.Right() - aSize.Width() - THUMBNAILVIEW_ITEM_CORNER, aArea.Top() + THUMBNAILVIEW_ITEM_CORNER),
137 aSize);
140 OUString RecentDocsViewItem::getHelpText() const
142 return m_sHelpText;
145 void RecentDocsViewItem::Paint(drawinglayer::processor2d::BaseProcessor2D *pProcessor, const ThumbnailItemAttributes *pAttrs)
147 ThumbnailViewItem::Paint(pProcessor, pAttrs);
149 // paint the remove icon when highlighted
150 if (isHighlighted())
152 drawinglayer::primitive2d::Primitive2DSequence aSeq(1);
154 Point aIconPos(getRemoveIconArea().TopLeft());
156 aSeq[0] = drawinglayer::primitive2d::Primitive2DReference(new DiscreteBitmapPrimitive2D(
157 m_bRemoveIconHighlighted ? m_aRemoveRecentBitmapHighlighted : m_aRemoveRecentBitmap,
158 B2DPoint(aIconPos.X(), aIconPos.Y())));
160 pProcessor->process(aSeq);
164 void RecentDocsViewItem::MouseButtonUp(const MouseEvent& rMEvt)
166 if (rMEvt.IsLeft())
168 if (getRemoveIconArea().IsInside(rMEvt.GetPosPixel()))
170 SvtHistoryOptions().DeleteItem(ePICKLIST, maURL);
171 mrParent.Reload();
172 return;
175 OpenDocument();
176 return;
180 void RecentDocsViewItem::OpenDocument()
182 // show busy mouse pointer
183 mrParent.SetPointer(Pointer(PointerStyle::Wait));
185 Reference<frame::XDispatch> xDispatch;
186 Reference<frame::XDispatchProvider> xDispatchProvider;
187 css::util::URL aTargetURL;
188 Sequence<beans::PropertyValue> aArgsList;
190 uno::Reference<frame::XDesktop2> xDesktop = frame::Desktop::create(::comphelper::getProcessComponentContext());
191 uno::Reference<frame::XFrame> xActiveFrame = xDesktop->getActiveFrame();
193 //osl::ClearableMutexGuard aLock(m_aMutex);
194 xDispatchProvider = Reference<frame::XDispatchProvider>(xActiveFrame, UNO_QUERY);
195 //aLock.clear();
197 aTargetURL.Complete = maURL;
198 Reference<util::XURLTransformer> xTrans(util::URLTransformer::create(::comphelper::getProcessComponentContext()));
199 xTrans->parseStrict(aTargetURL);
201 sal_Int32 nSize = 2;
202 aArgsList.realloc(nSize);
203 aArgsList[0].Name = "Referer";
204 aArgsList[0].Value = makeAny(OUString("private:user"));
206 // documents will never be opened as templates
207 aArgsList[1].Name = "AsTemplate";
208 aArgsList[1].Value = makeAny(false);
210 xDispatch = xDispatchProvider->queryDispatch(aTargetURL, "_default", 0);
212 if (xDispatch.is())
214 // Call dispatch asychronously as we can be destroyed while dispatch is
215 // executed. VCL is not able to survive this as it wants to call listeners
216 // after select!!!
217 LoadRecentFile* pLoadRecentFile = new LoadRecentFile;
218 pLoadRecentFile->xDispatch = xDispatch;
219 pLoadRecentFile->aTargetURL = aTargetURL;
220 pLoadRecentFile->aArgSeq = aArgsList;
222 Application::PostUserEvent(LINK(0, RecentDocsView, ExecuteHdl_Impl), pLoadRecentFile, true);
226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */