[Libreoffice-commits] core.git: cui/source include/sfx2 sfx2/source

Akshay Deep akshaydeepiitr at gmail.com
Tue Jul 25 19:27:22 UTC 2017


 cui/source/dialogs/cuicharmap.cxx |   79 ++++++++++++++++++++++++++++++++++++++
 cui/source/inc/cuicharmap.hxx     |    4 +
 include/sfx2/charwin.hxx          |   10 ++++
 include/sfx2/strings.hrc          |    3 +
 sfx2/source/control/charwin.cxx   |   55 ++++++++++++++++++++++++++
 5 files changed, 151 insertions(+)

New commits:
commit 06aacee86ec9e53928cc0c31906a8922babfe2b6
Author: Akshay Deep <akshaydeepiitr at gmail.com>
Date:   Thu Jul 20 19:08:28 2017 +0530

    Clear Recent View and Fav view using Right Click
    
    Conflicts:
            sfx2/inc/doc.hrc
            sfx2/source/doc/doc.src
    
    Change-Id: I0aa2919815a3fa63ee180b808834a8aa760af649
    Reviewed-on: https://gerrit.libreoffice.org/40234
    Reviewed-by: Akshay Deep <akshaydeepiitr at gmail.com>
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>

diff --git a/cui/source/dialogs/cuicharmap.cxx b/cui/source/dialogs/cuicharmap.cxx
index 500f0143e3ef..2b9fe879ab28 100644
--- a/cui/source/dialogs/cuicharmap.cxx
+++ b/cui/source/dialogs/cuicharmap.cxx
@@ -490,8 +490,12 @@ void SvxCharacterMap::init()
     for(int i = 0; i < 16; i++)
     {
         m_pRecentCharView[i]->setMouseClickHdl(LINK(this,SvxCharacterMap, CharClickHdl));
+        m_pRecentCharView[i]->setClearClickHdl(LINK(this,SvxCharacterMap, RecentClearClickHdl));
+        m_pRecentCharView[i]->setClearAllClickHdl(LINK(this,SvxCharacterMap, RecentClearAllClickHdl));
         m_pRecentCharView[i]->SetLoseFocusHdl(LINK(this,SvxCharacterMap, LoseFocusHdl));
         m_pFavCharView[i]->setMouseClickHdl(LINK(this,SvxCharacterMap, CharClickHdl));
+        m_pFavCharView[i]->setClearClickHdl(LINK(this,SvxCharacterMap, FavClearClickHdl));
+        m_pFavCharView[i]->setClearAllClickHdl(LINK(this,SvxCharacterMap, FavClearAllClickHdl));
         m_pFavCharView[i]->SetLoseFocusHdl(LINK(this,SvxCharacterMap, LoseFocusHdl));
     }
 }
@@ -662,6 +666,81 @@ IMPL_LINK_NOARG(SvxCharacterMap, SubsetSelectHdl, ListBox&, void)
     m_pSubsetLB->SelectEntryPos( nPos );
 }
 
+IMPL_LINK(SvxCharacterMap, RecentClearClickHdl, SvxCharView*, rView, void)
+{
+    OUString sTitle = rView->GetText();
+    auto itChar = std::find_if(maRecentCharList.begin(),
+         maRecentCharList.end(),
+         [sTitle] (const OUString & a) { return a == sTitle; });
+
+    OUString sFont = rView->GetFont().GetFamilyName();
+    auto itChar2 = std::find_if(maRecentCharFontList.begin(),
+         maRecentCharFontList.end(),
+         [sFont] (const OUString & a)
+         { return a == sFont; });
+
+    // if recent char to be added is already in list, remove it
+    if( itChar != maRecentCharList.end() &&  itChar2 != maRecentCharFontList.end() )
+    {
+        maRecentCharList.erase( itChar );
+        maRecentCharFontList.erase( itChar2);
+    }
+
+    css::uno::Sequence< OUString > aRecentCharList(maRecentCharList.size());
+    css::uno::Sequence< OUString > aRecentCharFontList(maRecentCharFontList.size());
+
+    for (size_t i = 0; i < maRecentCharList.size(); ++i)
+    {
+        aRecentCharList[i] = maRecentCharList[i];
+        aRecentCharFontList[i] = maRecentCharFontList[i];
+    }
+
+    std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create(mxContext));
+    officecfg::Office::Common::RecentCharacters::RecentCharacterList::set(aRecentCharList, batch);
+    officecfg::Office::Common::RecentCharacters::RecentCharacterFontList::set(aRecentCharFontList, batch);
+    batch->commit();
+
+    updateRecentCharControl();
+}
+
+IMPL_LINK_NOARG(SvxCharacterMap, RecentClearAllClickHdl, SvxCharView*, void)
+{
+    css::uno::Sequence< OUString > aRecentCharList(0);
+    css::uno::Sequence< OUString > aRecentCharFontList(0);
+
+    maRecentCharList.clear();
+    maRecentCharFontList.clear();
+
+    std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create(mxContext));
+    officecfg::Office::Common::RecentCharacters::RecentCharacterList::set(aRecentCharList, batch);
+    officecfg::Office::Common::RecentCharacters::RecentCharacterFontList::set(aRecentCharFontList, batch);
+    batch->commit();
+
+    updateRecentCharControl();
+}
+
+IMPL_LINK(SvxCharacterMap, FavClearClickHdl, SvxCharView*, rView, void)
+{
+    deleteFavCharacterFromList(rView->GetText(), rView->GetFont().GetFamilyName());
+    updateFavCharControl();
+}
+
+IMPL_LINK_NOARG(SvxCharacterMap, FavClearAllClickHdl, SvxCharView*, void)
+{
+    css::uno::Sequence< OUString > aFavCharList(0);
+    css::uno::Sequence< OUString > aFavCharFontList(0);
+
+    maFavCharList.clear();
+    maFavCharFontList.clear();
+
+    std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create(mxContext));
+    officecfg::Office::Common::FavoriteCharacters::FavoriteCharacterList::set(aFavCharList, batch);
+    officecfg::Office::Common::FavoriteCharacters::FavoriteCharacterFontList::set(aFavCharFontList, batch);
+    batch->commit();
+
+    updateFavCharControl();
+}
+
 IMPL_LINK(SvxCharacterMap, CharClickHdl, SvxCharView*, rView, void)
 {
     m_pShowChar->SetText( rView->GetText() );
diff --git a/cui/source/inc/cuicharmap.hxx b/cui/source/inc/cuicharmap.hxx
index ecf3d2cb709f..a79cd089177c 100644
--- a/cui/source/inc/cuicharmap.hxx
+++ b/cui/source/inc/cuicharmap.hxx
@@ -104,6 +104,10 @@ private:
     DECL_LINK(DecimalCodeChangeHdl, Edit&, void);
     DECL_LINK(HexCodeChangeHdl, Edit&, void);
     DECL_LINK(CharClickHdl, SvxCharView*, void);
+    DECL_LINK(RecentClearClickHdl, SvxCharView*, void);
+    DECL_LINK(FavClearClickHdl, SvxCharView*, void);
+    DECL_LINK(RecentClearAllClickHdl, SvxCharView*, void);
+    DECL_LINK(FavClearAllClickHdl, SvxCharView*, void);
     DECL_LINK(InsertClickHdl, Button*, void);
     DECL_STATIC_LINK(SvxCharacterMap, LoseFocusHdl, Control&, void);
     DECL_LINK(FavSelectHdl, Button*, void);
diff --git a/include/sfx2/charwin.hxx b/include/sfx2/charwin.hxx
index 2b58f5a0e9e1..51af2d7f56be 100644
--- a/include/sfx2/charwin.hxx
+++ b/include/sfx2/charwin.hxx
@@ -31,12 +31,19 @@ public:
     void            SetFont( const vcl::Font& rFont );
     void            SetText( const OUString& rText ) override;
     void            InsertCharToDoc();
+    Point           GetClickPosition() const;
+
+    void            createContextMenu();
 
     virtual void    Resize() override;
 
     virtual Size    GetOptimalSize() const override;
 
     void setMouseClickHdl(const Link<SvxCharView*,void> &rLink);
+    void setClearClickHdl(const Link<SvxCharView*,void> &rLink);
+    void setClearAllClickHdl(const Link<SvxCharView*,void> &rLink);
+
+    DECL_LINK(ContextMenuSelectHdl, Menu*, bool);
 
 protected:
     virtual void    Paint(vcl::RenderContext& rRenderContext, const ::tools::Rectangle&) override;
@@ -47,10 +54,13 @@ protected:
 
 private:
     long            mnY;
+    Point           maPosition;
     vcl::Font       maFont;
 
     Link<SvxCharView*, void> maInsertCharHdl;
     Link<SvxCharView*, void> maMouseClickHdl;
+    Link<SvxCharView*, void> maClearClickHdl;
+    Link<SvxCharView*, void> maClearAllClickHdl;
 };
 
 #endif
diff --git a/include/sfx2/strings.hrc b/include/sfx2/strings.hrc
index 1b0ea6ccb2ff..e72aa06253d1 100644
--- a/include/sfx2/strings.hrc
+++ b/include/sfx2/strings.hrc
@@ -276,6 +276,9 @@
 #define STR_TEMPLATE_NAME9                      NC_("STR_TEMPLATE_NAME9", "Sunset")
 #define STR_TEMPLATE_NAME10                     NC_("STR_TEMPLATE_NAME10", "Vintage")
 
+#define STR_CLEAR_CHAR                          NC_("STR_CLEAR_CHAR", "Clear")
+#define STR_CLEAR_ALL_CHAR                      NC_("STR_CLEAR_ALL_CHAR", "Clear All")
+
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sfx2/source/control/charwin.cxx b/sfx2/source/control/charwin.cxx
index 36f6eb15c581..184c841fbe09 100644
--- a/sfx2/source/control/charwin.cxx
+++ b/sfx2/source/control/charwin.cxx
@@ -24,6 +24,8 @@
 #include <comphelper/dispatchcommand.hxx>
 #include <comphelper/processfactory.hxx>
 #include <sfx2/app.hxx>
+#include <sfx2/sfxresid.hxx>
+#include <sfx2/strings.hrc>
 
 using namespace com::sun::star;
 
@@ -31,6 +33,7 @@ using namespace com::sun::star;
 SvxCharView::SvxCharView(vcl::Window* pParent)
     : Control(pParent, WB_TABSTOP | WB_BORDER)
     , mnY(0)
+    , maPosition(0,0)
 {
 }
 
@@ -49,6 +52,20 @@ void SvxCharView::MouseButtonDown( const MouseEvent& rMEvt )
 
         maMouseClickHdl.Call(this);
     }
+
+    if(rMEvt.IsRight())
+    {
+        Point aPosition (rMEvt.GetPosPixel());
+        maPosition = aPosition;
+        GrabFocus();
+        Invalidate();
+        createContextMenu();
+    }
+}
+
+Point SvxCharView::GetClickPosition() const
+{
+    return maPosition;
 }
 
 void SvxCharView::KeyInput( const KeyEvent& rKEvt )
@@ -82,6 +99,34 @@ void SvxCharView::InsertCharToDoc()
     comphelper::dispatchCommand(".uno:InsertSymbol", aArgs);
 }
 
+void SvxCharView::createContextMenu()
+{
+    ScopedVclPtrInstance<PopupMenu> pItemMenu;
+    pItemMenu->InsertItem(0,SfxResId(STR_CLEAR_CHAR));
+    pItemMenu->InsertItem(1,SfxResId(STR_CLEAR_ALL_CHAR));
+    pItemMenu->SetSelectHdl(LINK(this, SvxCharView, ContextMenuSelectHdl));
+    pItemMenu->Execute(this, tools::Rectangle(maPosition,Size(1,1)), PopupMenuFlags::ExecuteDown);
+    Invalidate();
+}
+
+IMPL_LINK(SvxCharView, ContextMenuSelectHdl, Menu*, pMenu, bool)
+{
+    sal_uInt16 nMenuId = pMenu->GetCurItemId();
+
+    switch(nMenuId)
+    {
+    case 0:
+        maClearClickHdl.Call(this);
+        break;
+    case 1:
+        maClearAllClickHdl.Call(this);
+        break;
+    default:
+        break;
+    }
+    return false;
+}
+
 void SvxCharView::Paint(vcl::RenderContext& rRenderContext, const ::tools::Rectangle&)
 {
     rRenderContext.SetFont(maFont);
@@ -171,6 +216,16 @@ void SvxCharView::setMouseClickHdl(const Link<SvxCharView*,void> &rLink)
     maMouseClickHdl = rLink;
 }
 
+void SvxCharView::setClearClickHdl(const Link<SvxCharView*,void> &rLink)
+{
+    maClearClickHdl = rLink;
+}
+
+void SvxCharView::setClearAllClickHdl(const Link<SvxCharView*,void> &rLink)
+{
+    maClearAllClickHdl = rLink;
+}
+
 void SvxCharView::SetFont( const vcl::Font& rFont )
 {
     long nWinHeight = GetOutputSizePixel().Height();


More information about the Libreoffice-commits mailing list