Skip to content

Commit

Permalink
startcenter: Add possibility to selectively remove recent documents.
Browse files Browse the repository at this point in the history
Change-Id: Id0c20de6dc3375e64dd3dbef34dcd6eb77f02340
  • Loading branch information
kendy committed Apr 26, 2014
1 parent 978ba69 commit 60cd850
Show file tree
Hide file tree
Showing 13 changed files with 265 additions and 94 deletions.
Binary file added icon-themes/galaxy/res/recentdoc_remove.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 10 additions & 5 deletions include/sfx2/recentdocsview.hxx
Expand Up @@ -38,15 +38,13 @@ enum ApplicationType
};


class SFX2_DLLPUBLIC RecentDocsView : protected ::comphelper::OBaseMutex,
public ThumbnailView
class SFX2_DLLPUBLIC RecentDocsView : public ThumbnailView
{
public:
RecentDocsView( Window* pParent );
virtual ~RecentDocsView();

void insertItem(const OUString &rURL, const OUString &rTitle, const BitmapEx &rThumbnail, sal_uInt16 nId);
void loadRecentDocs();

long GetThumbnailSize() const;

Expand All @@ -57,12 +55,18 @@ public:

virtual void Clear() SAL_OVERRIDE;

/// Update the information in the view.
virtual void Reload() SAL_OVERRIDE;

DECL_STATIC_LINK( RecentDocsView, ExecuteHdl_Impl, LoadRecentFile* );

protected:
virtual void MouseButtonDown( const MouseEvent& rMEvt ) SAL_OVERRIDE;

virtual void MouseButtonUp( const MouseEvent& rMEvt ) SAL_OVERRIDE;

virtual void OnItemDblClicked(ThumbnailViewItem *pItem) SAL_OVERRIDE;
void OpenItem( const ThumbnailViewItem *pItem );

virtual void Paint( const Rectangle& rRect ) SAL_OVERRIDE;

virtual void LoseFocus() SAL_OVERRIDE;
Expand All @@ -74,7 +78,8 @@ protected:
long mnItemPadding;
long mnItemMaxTextLength;

Image maWelcomeImage;
/// Image that appears when there is no recent document.
Image maWelcomeImage;
OUString maWelcomeLine1;
OUString maWelcomeLine2;
};
Expand Down
25 changes: 24 additions & 1 deletion include/sfx2/recentdocsviewitem.hxx
Expand Up @@ -19,13 +19,36 @@ public:
const OUString &rTitle, const BitmapEx& rThumbnail, sal_uInt16 nId);
virtual void setEditTitle (bool edit, bool bChangeFocus = true) SAL_OVERRIDE;

/** Updates own highlight status based on the aPoint position.
Calls the ancestor's updateHighlight, and then takes care of m_bRemoveIconHighlighted.
Returns rectangle that needs to be invalidated.
*/
virtual Rectangle updateHighlight(bool bVisible, const Point& rPoint) SAL_OVERRIDE;

/// Text to be used for the tooltip.
virtual OUString getHelpText() const SAL_OVERRIDE;

OUString maURL;
virtual void Paint(drawinglayer::processor2d::BaseProcessor2D *pProcessor,
const ThumbnailItemAttributes *pAttrs);

virtual void MouseButtonUp(const MouseEvent& rMEvt);

/// Called when the user clicks a document - it will open it.
void OpenDocument();

protected:
/// Return area where is the icon to remove document from the recent documents.
Rectangle getRemoveIconArea() const;

private:
OUString maURL;

OUString m_sHelpText;

/// Is the icon that the user can click to remove the document from the recent documents highlighted?
bool m_bRemoveIconHighlighted;
};

#endif // INCLUDED_SFX2_RECENTDOCSVIEWITEM_HXX
Expand Down
13 changes: 8 additions & 5 deletions include/sfx2/thumbnailview.hxx
Expand Up @@ -180,18 +180,21 @@ class SFX2_DLLPUBLIC ThumbnailView : public Control
{
public:

ThumbnailView ( Window* pParent, WinBits nWinStyle = WB_TABSTOP, bool bDisableTransientChildren = false );
ThumbnailView(Window* pParent, WinBits nWinStyle = WB_TABSTOP, bool bDisableTransientChildren = false);

virtual ~ThumbnailView ();
virtual ~ThumbnailView();

virtual void MouseMove( const MouseEvent& rMEvt ) SAL_OVERRIDE;
virtual void MouseMove(const MouseEvent& rMEvt) SAL_OVERRIDE;

void AppendItem (ThumbnailViewItem *pItem);
void AppendItem(ThumbnailViewItem *pItem);

void RemoveItem( sal_uInt16 nItemId );
void RemoveItem(sal_uInt16 nItemId);

virtual void Clear();

/// Updates information in the view; used only in RecentDocsView ATM.
virtual void Reload() {}

// Change current thumbnail item list with new one (invalidates all pointers to a thumbnail item)
void updateItems(const std::vector<ThumbnailViewItem *> &items);

Expand Down
10 changes: 10 additions & 0 deletions include/sfx2/thumbnailviewitem.hxx
Expand Up @@ -32,6 +32,8 @@

#define THUMBNAILVIEW_ITEM_NONEITEM 0xFFFE

const int THUMBNAILVIEW_ITEM_CORNER = 5;

class CheckBox;
class Font;
class Window;
Expand Down Expand Up @@ -89,6 +91,12 @@ public:

void setHighlight (bool state);

/** Updates own highlight status based on the aPoint position.
Returns rectangle that needs to be invalidated.
*/
virtual Rectangle updateHighlight(bool bVisible, const Point& rPoint);

/// Text to be used for the tooltip.
virtual OUString getHelpText() const;

Expand Down Expand Up @@ -121,6 +129,8 @@ public:
static drawinglayer::primitive2d::PolygonHairlinePrimitive2D*
createBorderLine (const basegfx::B2DPolygon &rPolygon);

virtual void MouseButtonUp(const MouseEvent&) {}

protected:

Point maTextPos;
Expand Down
76 changes: 15 additions & 61 deletions sfx2/source/control/recentdocsview.cxx
Expand Up @@ -26,7 +26,6 @@
#include <unotools/historyoptions.hxx>
#include <vcl/builder.hxx>
#include <vcl/pngread.hxx>
#include <vcl/svapp.hxx>
#include <tools/urlobj.hxx>
#include <com/sun/star/util/URLTransformer.hpp>
#include <com/sun/star/frame/Desktop.hpp>
Expand Down Expand Up @@ -148,7 +147,7 @@ void RecentDocsView::insertItem(const OUString &rURL, const OUString &rTitle, co
AppendItem(pChild);
}

void RecentDocsView::loadRecentDocs()
void RecentDocsView::Reload()
{
Clear();

Expand Down Expand Up @@ -212,78 +211,33 @@ void RecentDocsView::loadRecentDocs()

void RecentDocsView::MouseButtonDown( const MouseEvent& rMEvt )
{
if ( rMEvt.IsLeft() )
if (rMEvt.IsLeft())
{
if( rMEvt.GetClicks() > 1 )
return;
// ignore to avoid stuff done in ThumbnailView; we don't do selections etc.
return;
}

ThumbnailView::MouseButtonDown(rMEvt);
}

void RecentDocsView::MouseButtonUp(const MouseEvent& rMEvt)
{
if (rMEvt.IsLeft())
{
size_t nPos = ImplGetItem(rMEvt.GetPosPixel());
ThumbnailViewItem* pItem = ImplGetItem(nPos);

if (pItem)
{
OpenItem(pItem);
pItem->MouseButtonUp(rMEvt);
return;
}
}
ThumbnailView::MouseButtonDown( rMEvt );
ThumbnailView::MouseButtonUp(rMEvt);
}

void RecentDocsView::OnItemDblClicked(ThumbnailViewItem *pItem)
void RecentDocsView::OnItemDblClicked(ThumbnailViewItem *)
{
OpenItem( pItem );
}

void RecentDocsView::OpenItem( const ThumbnailViewItem *pItem )
{
const RecentDocsViewItem* pRecentItem = dynamic_cast<const RecentDocsViewItem*>(pItem);
if (!pRecentItem)
return;

// show busy mouse pointer
SetPointer(Pointer(POINTER_WAIT));

Reference< XDispatch > xDispatch;
Reference< XDispatchProvider > xDispatchProvider;
css::util::URL aTargetURL;
Sequence< PropertyValue > aArgsList;

uno::Reference< frame::XDesktop2 > xDesktop = frame::Desktop::create( ::comphelper::getProcessComponentContext() );
uno::Reference< frame::XFrame > xActiveFrame = xDesktop->getActiveFrame();

osl::ClearableMutexGuard aLock( m_aMutex );
xDispatchProvider = Reference< XDispatchProvider >( xActiveFrame, UNO_QUERY );
aLock.clear();

aTargetURL.Complete = pRecentItem->maURL;
Reference< ::com::sun::star::util::XURLTransformer > xTrans(
::com::sun::star::util::URLTransformer::create(
::comphelper::getProcessComponentContext() ) );
xTrans->parseStrict( aTargetURL );

sal_Int32 nSize = 2;
aArgsList.realloc( nSize );
aArgsList[0].Name = "Referer";
aArgsList[0].Value = makeAny( OUString( "private:user" ) );

// documents will never be opened as templates
aArgsList[1].Name = "AsTemplate";
aArgsList[1].Value = makeAny( false );

xDispatch = xDispatchProvider->queryDispatch( aTargetURL, "_default", 0 );

if ( xDispatch.is() )
{
// Call dispatch asychronously as we can be destroyed while dispatch is
// executed. VCL is not able to survive this as it wants to call listeners
// after select!!!
LoadRecentFile* pLoadRecentFile = new LoadRecentFile;
pLoadRecentFile->xDispatch = xDispatch;
pLoadRecentFile->aTargetURL = aTargetURL;
pLoadRecentFile->aArgSeq = aArgsList;

Application::PostUserEvent( STATIC_LINK(0, RecentDocsView, ExecuteHdl_Impl), pLoadRecentFile );
}
}

void RecentDocsView::Paint( const Rectangle &aRect )
Expand Down

0 comments on commit 60cd850

Please sign in to comment.