LibreOffice Module sfx2 (master) 1
recentdocsview.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 <sal/log.hxx>
22#include <recentdocsview.hxx>
23#include <sfx2/sfxresid.hxx>
25#include <vcl/event.hxx>
26#include <vcl/ptrstyle.hxx>
27#include <vcl/svapp.hxx>
28#include <tools/urlobj.hxx>
29#include <com/sun/star/frame/XDispatch.hpp>
30#include <sfx2/strings.hrc>
31#include <bitmaps.hlst>
33#include <sfx2/app.hxx>
34
35#include <officecfg/Office/Common.hxx>
36
37#include <map>
38
39using namespace ::com::sun::star;
40using namespace com::sun::star::uno;
41using namespace com::sun::star::lang;
42using namespace com::sun::star::beans;
43
44namespace {
45
47void SetMessageFont(vcl::RenderContext& rRenderContext)
48{
49 vcl::Font aFont(rRenderContext.GetFont());
50 aFont.SetFontHeight(aFont.GetFontHeight() * 1.3);
51 rRenderContext.SetFont(aFont);
52}
53
54}
55
56namespace sfx2
57{
58
61
62RecentDocsView::RecentDocsView(std::unique_ptr<weld::ScrolledWindow> xWindow, std::unique_ptr<weld::Menu> xMenu)
63 : ThumbnailView(std::move(xWindow), std::move(xMenu))
64 , mnFileTypes(ApplicationType::TYPE_NONE)
65 , mnLastMouseDownItem(THUMBNAILVIEW_ITEM_NOTFOUND)
66 , maWelcomeLine1(SfxResId(STR_WELCOME_LINE1))
67 , maWelcomeLine2(SfxResId(STR_WELCOME_LINE2))
68 , mpLoadRecentFile(nullptr)
69 , m_nExecuteHdlId(nullptr)
70{
72 mnItemMaxSize = std::min(aScreen.GetWidth(),aScreen.GetHeight()) > 800 ? 256 : 192;
73
76
77 maFillColor = Color(ColorTransparency, officecfg::Office::Common::Help::StartCenter::StartCenterThumbnailsBackgroundColor::get());
78 maTextColor = Color(ColorTransparency, officecfg::Office::Common::Help::StartCenter::StartCenterThumbnailsTextColor::get());
79 maHighlightColor = Color(ColorTransparency, officecfg::Office::Common::Help::StartCenter::StartCenterThumbnailsHighlightColor::get());
80 maHighlightTextColor = Color(ColorTransparency, officecfg::Office::Common::Help::StartCenter::StartCenterThumbnailsHighlightTextColor::get());
82
84}
85
87{
89 m_nExecuteHdlId = nullptr;
91 {
92 mpLoadRecentFile->pView = nullptr;
93 mpLoadRecentFile = nullptr;
94 }
95}
96
97bool RecentDocsView::typeMatchesExtension(ApplicationType type, std::u16string_view rExt)
98{
99 bool bRet = false;
100
101 if (rExt == u"odt" || rExt == u"fodt" || rExt == u"doc" || rExt == u"docx" ||
102 rExt == u"rtf" || rExt == u"txt" || rExt == u"odm" || rExt == u"otm")
103 {
104 bRet = static_cast<bool>(type & ApplicationType::TYPE_WRITER);
105 }
106 else if (rExt == u"ods" || rExt == u"fods" || rExt == u"xls" || rExt == u"xlsx")
107 {
108 bRet = static_cast<bool>(type & ApplicationType::TYPE_CALC);
109 }
110 else if (rExt == u"odp" || rExt == u"fodp" || rExt == u"pps" || rExt == u"ppt" ||
111 rExt == u"pptx")
112 {
113 bRet = static_cast<bool>(type & ApplicationType::TYPE_IMPRESS);
114 }
115 else if (rExt == u"odg" || rExt == u"fodg")
116 {
117 bRet = static_cast<bool>(type & ApplicationType::TYPE_DRAW);
118 }
119 else if (rExt == u"odb")
120 {
121 bRet = static_cast<bool>(type & ApplicationType::TYPE_DATABASE);
122 }
123 else if (rExt == u"odf")
124 {
125 bRet = static_cast<bool>(type & ApplicationType::TYPE_MATH);
126 }
127 else
128 {
129 bRet = static_cast<bool>(type & ApplicationType::TYPE_OTHER);
130 }
131
132 return bRet;
133}
134
136{
137 const OUString aExt = rURL.getExtension();
145}
146
147void RecentDocsView::insertItem(const OUString& rURL, const OUString& rTitle,
148 const OUString& rThumbnail, bool isReadOnly, bool isPinned,
149 sal_uInt16 nId)
150{
151 AppendItem(std::make_unique<RecentDocsViewItem>(*this, rURL, rTitle, rThumbnail, nId,
152 mnItemMaxSize, isReadOnly, isPinned));
153}
154
156{
157 Clear();
158
159 std::vector< SvtHistoryOptions::HistoryItem > aHistoryList = SvtHistoryOptions::GetList( EHistoryType::PickList );
160 for ( size_t i = 0; i < aHistoryList.size(); i++ )
161 {
162 const SvtHistoryOptions::HistoryItem& rRecentEntry = aHistoryList[i];
163
164 OUString aURL = rRecentEntry.sURL;
165 const INetURLObject aURLObj(aURL);
166
168 (!isAcceptedFile(aURLObj)))
169 continue;
170
171 //Remove extension from url's last segment and use it as title
172 const OUString aTitle = aURLObj.GetBase(); //DecodeMechanism::WithCharset
173
174 insertItem(aURL, aTitle, rRecentEntry.sThumbnail, rRecentEntry.isReadOnly,
175 rRecentEntry.isPinned, i + 1);
176 }
177
179 Invalidate();
180}
181
183{
184 mnFileTypes = aFilter;
185 Reload();
186}
187
189 std::vector< SvtHistoryOptions::HistoryItem > aHistoryList = SvtHistoryOptions::GetList( EHistoryType::PickList );
190 for ( size_t i = 0; i < aHistoryList.size(); i++ )
191 {
192 const SvtHistoryOptions::HistoryItem& rPickListEntry = aHistoryList[i];
193 if ( !comphelper::DirectoryHelper::fileExists(rPickListEntry.sURL) ){
194 SvtHistoryOptions::DeleteItem(EHistoryType::PickList,rPickListEntry.sURL);
195 }
196 }
197 Reload();
198}
199
201{
202 if (rMEvt.IsLeft())
203 {
205
206 // ignore to avoid stuff done in ThumbnailView; we don't do selections etc.
207 return true;
208 }
209
210 return ThumbnailView::MouseButtonDown(rMEvt);
211}
212
214{
215 if (rMEvt.IsLeft())
216 {
217 if( rMEvt.GetClicks() > 1 )
218 return true;
219
220 size_t nPos = ImplGetItem(rMEvt.GetPosPixel());
222
223 if (pItem && nPos == mnLastMouseDownItem)
224 {
225 pItem->MouseButtonUp(rMEvt);
226
228 if(pNewItem)
229 pNewItem->setHighlight(true);
230 }
231
233
234 if (pItem)
235 return true;
236 }
237 return ThumbnailView::MouseButtonUp(rMEvt);
238}
239
241{
242 RecentDocsViewItem* pRecentItem = dynamic_cast< RecentDocsViewItem* >(pItem);
243 if (pRecentItem)
244 pRecentItem->OpenDocument();
245}
246
248{
249 ThumbnailView::Paint(rRenderContext, aRect);
250
251 if (!mItemList.empty())
252 return;
253
255 {
256 const tools::Long aWidth(aRect.GetWidth() > aRect.getOpenHeight() ? aRect.GetHeight()/2 : aRect.GetWidth()/2);
258 }
259
260 // No recent files to be shown yet. Show a welcome screen.
262 SetMessageFont(rRenderContext);
263 rRenderContext.SetTextColor(maTextColor);
264
265 tools::Long nTextHeight = rRenderContext.GetTextHeight();
266
267 const Size& rImgSize = maWelcomeImage.GetSizePixel();
268 const Size& rSize = GetOutputSizePixel();
269
270 const int nX = (rSize.Width() - rImgSize.Width())/2;
271 int nY = (rSize.Height() - 3 * nTextHeight - rImgSize.Height())/2;
272 Point aImgPoint(nX, nY);
273 rRenderContext.DrawBitmapEx(aImgPoint, rImgSize, maWelcomeImage);
274
275 nY = nY + rImgSize.Height();
276 rRenderContext.DrawText(tools::Rectangle(0, nY + 1 * nTextHeight, rSize.Width(), nY + nTextHeight),
278 DrawTextFlags::Center);
279 rRenderContext.DrawText(tools::Rectangle(0, nY + 2 * nTextHeight, rSize.Width(), rSize.Height()),
281 DrawTextFlags::MultiLine | DrawTextFlags::WordBreak | DrawTextFlags::Center);
282
283 rRenderContext.Pop();
284}
285
287{
289
291}
292
294{
295 Invalidate();
297}
298
300{
301 assert(!mpLoadRecentFile);
302 mpLoadRecentFile = pLoadRecentFile;
303 m_nExecuteHdlId = Application::PostUserEvent(LINK(this, RecentDocsView, ExecuteHdl_Impl), pLoadRecentFile);
304}
305
307{
308 mpLoadRecentFile = nullptr;
309}
310
311IMPL_LINK( RecentDocsView, ExecuteHdl_Impl, void*, p, void )
312{
313 m_nExecuteHdlId = nullptr;
314 LoadRecentFile* pLoadRecentFile = static_cast<LoadRecentFile*>(p);
315 try
316 {
317 // Asynchronous execution as this can lead to our own destruction!
318 // Framework can recycle our current frame and the layout manager disposes all user interface
319 // elements if a component gets detached from its frame!
320 pLoadRecentFile->xDispatch->dispatch( pLoadRecentFile->aTargetURL, pLoadRecentFile->aArgSeq );
321 }
322 catch ( const Exception& )
323 {
324 }
325
326 if (pLoadRecentFile->pView)
327 {
328 pLoadRecentFile->pView->DispatchedLoadRecentUsedFile();
329 pLoadRecentFile->pView->SetPointer(PointerStyle::Arrow);
330 pLoadRecentFile->pView->Enable();
331 }
332
333 delete pLoadRecentFile;
334}
335
336} // namespace sfx2
337
338/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static unsigned int GetDisplayBuiltInScreen()
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
static void RemoveUserEvent(ImplSVEvent *nUserEvent)
static tools::Rectangle GetScreenPosSizePixel(unsigned int nScreen)
bool IsEmpty() const
const Size & GetSizePixel() const
OUString getExtension(sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true, DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
OUString GetBase() const
sal_uInt16 GetClicks() const
const Point & GetPosPixel() const
bool IsLeft() const
const vcl::Font & GetFont() const
void DrawBitmapEx(const Point &rDestPt, const BitmapEx &rBitmapEx)
void SetFont(const vcl::Font &rNewFont)
void SetTextColor(const Color &rColor)
void Push(vcl::PushFlags nFlags=vcl::PushFlags::ALL)
tools::Long GetTextHeight() const
void DrawText(const Point &rStartPt, const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, std::vector< tools::Rectangle > *pVector=nullptr, OUString *pDisplayText=nullptr, const SalLayoutGlyphs *pLayoutCache=nullptr)
void OpenDocument()
Called when the user clicks a document - it will open it.
static BitmapEx GetApplicationLogo(tools::Long nWidth)
loads the application logo as used in the impress slideshow pause screen
Definition: appmisc.cxx:204
constexpr tools::Long Height() const
constexpr tools::Long Width() const
virtual void MouseButtonUp(const MouseEvent &)
void setHighlight(bool state)
Class to display thumbnails with their names below their respective icons.
void CalculateItemPositions(bool bScrollBarUsed=false)
void deselectItems()
deselect all current selected items.
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
size_t ImplGetItem(const Point &rPoint) const
Color maHighlightColor
Color of the highlight (background) of the hovered item.
void AppendItem(std::unique_ptr< ThumbnailViewItem > pItem)
double mfHighlightTransparence
Transparence of the highlight.
virtual void Clear()
Color maHighlightTextColor
Color of the text for the highlighted item.
void setItemDimensions(tools::Long ItemWidth, tools::Long ThumbnailHeight, tools::Long DisplayHeight, int itemPadding)
virtual void LoseFocus() override
Color maTextColor
Text color.
void setItemMaxTextLength(sal_uInt32 nLength)
std::vector< std::unique_ptr< ThumbnailViewItem > > mItemList
Color maFillColor
Background color of the thumbnail view widget.
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect) override
static bool fileExists(const OUString &rBaseURL)
void setFilter(ApplicationType aFilter)
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect) override
sfx2::LoadRecentFile * mpLoadRecentFile
virtual void OnItemDblClicked(ThumbnailViewItem *pItem) override
void PostLoadRecentUsedFile(LoadRecentFile *pLoadRecentFile)
ApplicationType mnFileTypes
void insertItem(const OUString &rURL, const OUString &rTitle, const OUString &rThumbnail, bool isReadOnly, bool isPinned, sal_uInt16 nId)
virtual ~RecentDocsView() override
virtual void LoseFocus() override
static bool typeMatchesExtension(ApplicationType type, std::u16string_view rExt)
BitmapEx maWelcomeImage
Image that appears when there is no recent document.
virtual void Reload() override
Update the information in the view.
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
ImplSVEvent * m_nExecuteHdlId
virtual bool MouseButtonUp(const MouseEvent &rMEvt) override
bool isAcceptedFile(const INetURLObject &rURL) const
RecentDocsView(std::unique_ptr< weld::ScrolledWindow > xWindow, std::unique_ptr< weld::Menu > xMenu)
virtual void Clear() override
constexpr tools::Long GetWidth() const
tools::Long getOpenHeight() const
constexpr tools::Long GetHeight() const
void SetPointer(PointerStyle ePointerStyle)
virtual bool MouseButtonUp(const MouseEvent &)
Size const & GetOutputSizePixel() const
ColorTransparency
URL aURL
float u
void * p
sal_uInt16 nPos
Definition: linksrc.cxx:118
void DeleteItem(EHistoryType eHistory, const OUString &sURL)
std::vector< HistoryItem > GetList(EHistoryType eHistory)
@ Exception
int i
IMPL_LINK(SvDDEObject, ImplGetDDEData, const DdeData *, pData, void)
Definition: impldde.cxx:285
constexpr tools::Long gnTextHeight
constexpr tools::Long gnItemPadding
long Long
sal_Int16 nId
OUString SfxResId(TranslateId aId)
Definition: sfxresid.cxx:22
css::uno::Sequence< css::beans::PropertyValue > aArgSeq
css::uno::Reference< css::frame::XDispatch > xDispatch
RecentDocsView * pView
css::util::URL aTargetURL
#define THUMBNAILVIEW_ITEM_NOTFOUND
ResultType type