[Libreoffice-commits] core.git: cui/source include/svx include/vcl svx/source vcl/source
Akshay Deep
akshaydeepiitr at gmail.com
Tue Aug 15 19:13:41 UTC 2017
cui/source/dialogs/cuicharmap.cxx | 12 ++
cui/source/inc/cuicharmap.hxx | 1
include/svx/charmap.hxx | 19 +++
include/svx/strings.hrc | 5
include/vcl/textview.hxx | 26 ++++
svx/source/dialog/charmap.cxx | 202 +++++++++++++++++++++++++++++++++++-
svx/source/dialog/searchcharmap.cxx | 1
vcl/source/edit/textview.cxx | 25 ----
8 files changed, 264 insertions(+), 27 deletions(-)
New commits:
commit f9af8a35fc1aad055af2b5e6b6eab45a7d060719
Author: Akshay Deep <akshaydeepiitr at gmail.com>
Date: Tue Aug 15 17:21:26 2017 +0000
tdf#111337 - Introduce alternative workflows at the special characters dialog
Change-Id: I6a8fe2476adc5c4379c76dfaef090d1b5cd81ea0
Reviewed-on: https://gerrit.libreoffice.org/41170
Reviewed-by: Heiko Tietze <tietze.heiko at googlemail.com>
Tested-by: Heiko Tietze <tietze.heiko at googlemail.com>
diff --git a/cui/source/dialogs/cuicharmap.cxx b/cui/source/dialogs/cuicharmap.cxx
index d148676dc645..0831604b408b 100644
--- a/cui/source/dialogs/cuicharmap.cxx
+++ b/cui/source/dialogs/cuicharmap.cxx
@@ -243,6 +243,8 @@ void SvxCharacterMap::getRecentCharacterList()
void SvxCharacterMap::getFavCharacterList()
{
+ maFavCharList.clear();
+ maFavCharFontList.clear();
//retrieve recent character list
css::uno::Sequence< OUString > rFavCharList( officecfg::Office::Common::FavoriteCharacters::FavoriteCharacterList::get() );
for (int i = 0; i < rFavCharList.getLength(); ++i)
@@ -385,6 +387,8 @@ void SvxCharacterMap::updateFavCharControl()
m_pFavCharView[i]->SetText(OUString());
m_pFavCharView[i]->Hide();
}
+ m_pShowSet->getFavCharacterList();
+ m_pSearchSet->getFavCharacterList();
}
@@ -476,11 +480,13 @@ void SvxCharacterMap::init()
m_pShowSet->SetSelectHdl( LINK( this, SvxCharacterMap, CharSelectHdl ) );
m_pShowSet->SetHighlightHdl( LINK( this, SvxCharacterMap, CharHighlightHdl ) );
m_pShowSet->SetPreSelectHdl( LINK( this, SvxCharacterMap, CharPreSelectHdl ) );
+ m_pShowSet->SetFavClickHdl( LINK( this, SvxCharacterMap, FavClickHdl ) );
m_pSearchSet->SetDoubleClickHdl( LINK( this, SvxCharacterMap, SearchCharDoubleClickHdl ) );
m_pSearchSet->SetSelectHdl( LINK( this, SvxCharacterMap, SearchCharSelectHdl ) );
m_pSearchSet->SetHighlightHdl( LINK( this, SvxCharacterMap, SearchCharHighlightHdl ) );
m_pSearchSet->SetPreSelectHdl( LINK( this, SvxCharacterMap, SearchCharPreSelectHdl ) );
+ m_pSearchSet->SetFavClickHdl( LINK( this, SvxCharacterMap, FavClickHdl ) );
m_pDecimalCodeText->SetModifyHdl( LINK( this, SvxCharacterMap, DecimalCodeChangeHdl ) );
m_pHexCodeText->SetModifyHdl( LINK( this, SvxCharacterMap, HexCodeChangeHdl ) );
@@ -955,6 +961,12 @@ IMPL_LINK_NOARG(SvxCharacterMap, FavSelectHdl, Button*, void)
updateFavCharControl();
}
+IMPL_LINK_NOARG(SvxCharacterMap, FavClickHdl, SvxShowCharSet*, void)
+{
+ getFavCharacterList();
+ updateFavCharControl();
+}
+
IMPL_LINK_NOARG(SvxCharacterMap, CharHighlightHdl, SvxShowCharSet*, void)
{
OUString aText;
diff --git a/cui/source/inc/cuicharmap.hxx b/cui/source/inc/cuicharmap.hxx
index e7c63c29429c..2ba12e34f212 100644
--- a/cui/source/inc/cuicharmap.hxx
+++ b/cui/source/inc/cuicharmap.hxx
@@ -106,6 +106,7 @@ private:
DECL_LINK(CharSelectHdl, SvxShowCharSet*, void);
DECL_LINK(CharHighlightHdl, SvxShowCharSet*, void);
DECL_LINK(CharPreSelectHdl, SvxShowCharSet*, void);
+ DECL_LINK(FavClickHdl, SvxShowCharSet*,void);
DECL_LINK(SearchCharDoubleClickHdl, SvxShowCharSet*,void);
DECL_LINK(SearchCharSelectHdl, SvxShowCharSet*, void);
DECL_LINK(SearchCharHighlightHdl, SvxShowCharSet*, void);
diff --git a/include/svx/charmap.hxx b/include/svx/charmap.hxx
index 86c95fc0cad5..bee07bbad2aa 100644
--- a/include/svx/charmap.hxx
+++ b/include/svx/charmap.hxx
@@ -33,6 +33,7 @@
#include <vcl/metric.hxx>
#include <vcl/vclptr.hxx>
#include <vcl/window.hxx>
+#include <vcl/textview.hxx>
namespace com { namespace sun { namespace star {
namespace accessibility { class XAccessible; }
@@ -40,6 +41,8 @@ namespace com { namespace sun { namespace star {
namespace vcl { class Font; }
+using namespace ::com::sun::star;
+
#define COLUMN_COUNT 16
#define ROW_COUNT 8
@@ -62,15 +65,20 @@ public:
virtual void RecalculateFont(vcl::RenderContext& rRenderContext);
- void SelectCharacter( sal_uInt32 cNew );
+ void SelectCharacter( sal_uInt32 cNew );
virtual sal_UCS4 GetSelectCharacter() const;
+ void createContextMenu();
void SetDoubleClickHdl( const Link<SvxShowCharSet*,void>& rLink ) { aDoubleClkHdl = rLink; }
void SetSelectHdl( const Link<SvxShowCharSet*,void>& rHdl ) { aSelectHdl = rHdl; }
void SetHighlightHdl( const Link<SvxShowCharSet*,void>& rHdl ) { aHighHdl = rHdl; }
void SetPreSelectHdl( const Link<SvxShowCharSet*,void>& rHdl ) { aPreSelectHdl = rHdl; }
+ void SetFavClickHdl( const Link<SvxShowCharSet*,void>& rHdl ) { aFavClickHdl = rHdl; }
static sal_uInt32& getSelectedChar();
void SetFont( const vcl::Font& rFont );
+ bool isFavChar(const OUString& sTitle, const OUString& rFont);
+ void getFavCharacterList(); //gets both Fav char and Fav char font list
+ void updateFavCharacterList(const OUString& rChar, const OUString& rFont);
virtual svx::SvxShowCharSetItem* ImplGetItem( int _nPos );
int FirstInView() const;
@@ -79,6 +87,7 @@ public:
virtual void SelectIndex( int index, bool bFocus = false );
void OutputIndex( int index );
void DeSelect();
+ void CopyToClipboard(const OUString& str);
bool IsSelected(sal_uInt16 _nPos) const { return _nPos == nSelectedIndex; }
sal_uInt16 GetSelectIndexId() const { return sal::static_int_cast<sal_uInt16>(nSelectedIndex); }
static sal_uInt16 GetRowPos(sal_uInt16 _nPos);
@@ -111,9 +120,15 @@ protected:
ItemsMap m_aItems;
Link<SvxShowCharSet*,void> aDoubleClkHdl;
Link<SvxShowCharSet*,void> aSelectHdl;
+ Link<SvxShowCharSet*,void> aFavClickHdl;
Link<SvxShowCharSet*,void> aHighHdl;
Link<SvxShowCharSet*,void> aPreSelectHdl;
+
+ std::deque<OUString> maFavCharList;
+ std::deque<OUString> maFavCharFontList;
+
rtl::Reference<svx::SvxShowCharSetVirtualAcc> m_xAccessible;
+ uno::Reference< uno::XComponentContext > mxContext;
long nX;
long nY;
long m_nXGap;
@@ -124,6 +139,7 @@ protected:
FontCharMapRef mxFontCharMap;
Size maFontSize;
+ Point maPosition;
VclPtr<ScrollBar> aVscrollSB;
bool mbRecalculateFont : 1;
@@ -137,6 +153,7 @@ protected:
// abstraction layers are: Unicode<->MapIndex<->Pixel
Point MapIndexToPixel( int) const;
DECL_LINK(VscrollHdl, ScrollBar*, void);
+ DECL_LINK(ContextMenuSelectHdl, Menu*, bool);
void init();
tools::Rectangle getGridRectangle(const Point &rPointUL, const Size &rOutputSize);
diff --git a/include/svx/strings.hrc b/include/svx/strings.hrc
index a706fa6d0c61..5b412117adb2 100644
--- a/include/svx/strings.hrc
+++ b/include/svx/strings.hrc
@@ -1256,6 +1256,11 @@
// String for saving modified image (instead of original)
#define RID_SVXSTR_SAVE_MODIFIED_IMAGE NC_("RID_SVXSTR_SAVE_MODIFIED_IMAGE", "The image has been modified. By default the original image will be saved.\nDo you want to save the modified version instead ?")
+#define RID_ADD_TO_FAVORITES NC_("RID_SUBSETMAP", "Add to favorites")
+#define RID_REMOVE_FAVORITES NC_("RID_SUBSETMAP", "Remove from favorites")
+#define RID_INSERT NC_("RID_SUBSETMAP", "Insert into document")
+#define RID_COPY_CLIPBOARD NC_("RID_SUBSETMAP", "Copy to clipboard")
+
#define RID_SUBSETSTR_BASIC_LATIN NC_("RID_SUBSETMAP", "Basic Latin")
#define RID_SUBSETSTR_LATIN_1 NC_("RID_SUBSETMAP", "Latin-1")
#define RID_SUBSETSTR_LATIN_EXTENDED_A NC_("RID_SUBSETMAP", "Latin Extended-A")
diff --git a/include/vcl/textview.hxx b/include/vcl/textview.hxx
index 76e8e7ccbac5..9688d9544782 100644
--- a/include/vcl/textview.hxx
+++ b/include/vcl/textview.hxx
@@ -51,6 +51,32 @@ namespace i18nutil {
struct ImpTextView;
class ExtTextEngine;
+class VCL_DLLPUBLIC TETextDataObject : public css::datatransfer::XTransferable,
+ public ::cppu::OWeakObject
+
+{
+private:
+ OUString maText;
+ SvMemoryStream maHTMLStream;
+
+public:
+ explicit TETextDataObject( const OUString& rText );
+
+ OUString& GetText() { return maText; }
+ SvMemoryStream& GetHTMLStream() { return maHTMLStream; }
+
+ // css::uno::XInterface
+ css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override;
+ void SAL_CALL acquire() throw() override { OWeakObject::acquire(); }
+ void SAL_CALL release() throw() override { OWeakObject::release(); }
+
+ // css::datatransfer::XTransferable
+ css::uno::Any SAL_CALL getTransferData( const css::datatransfer::DataFlavor& aFlavor ) override;
+ css::uno::Sequence< css::datatransfer::DataFlavor > SAL_CALL getTransferDataFlavors( ) override;
+ sal_Bool SAL_CALL isDataFlavorSupported( const css::datatransfer::DataFlavor& aFlavor ) override;
+};
+
+
class VCL_DLLPUBLIC TextView : public vcl::unohelper::DragAndDropClient
{
friend class TextEngine;
diff --git a/svx/source/dialog/charmap.cxx b/svx/source/dialog/charmap.cxx
index d997ab7e90ae..110b488c4483 100644
--- a/svx/source/dialog/charmap.cxx
+++ b/svx/source/dialog/charmap.cxx
@@ -40,16 +40,22 @@
#include <com/sun/star/accessibility/AccessibleEventObject.hpp>
#include <com/sun/star/accessibility/AccessibleEventId.hpp>
#include <com/sun/star/accessibility/AccessibleStateType.hpp>
+#include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
+#include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp>
+#include <officecfg/Office/Common.hxx>
+#include <comphelper/processfactory.hxx>
+#include <comphelper/dispatchcommand.hxx>
+#include <comphelper/propertysequence.hxx>
#include <comphelper/types.hxx>
#include <svl/itemset.hxx>
#include <unicode/uchar.h>
+#include <vcl/textview.hxx>
#include "rtl/ustrbuf.hxx"
using namespace ::com::sun::star::accessibility;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star;
-
sal_uInt32& SvxShowCharSet::getSelectedChar()
{
static sal_uInt32 cSelectedChar = ' '; // keeps selected character over app lifetime
@@ -58,7 +64,9 @@ sal_uInt32& SvxShowCharSet::getSelectedChar()
SvxShowCharSet::SvxShowCharSet(vcl::Window* pParent)
: Control(pParent, WB_TABSTOP | WB_BORDER)
+ , mxContext(comphelper::getProcessComponentContext())
, maFontSize(0, 0)
+ , maPosition(0,0)
, aVscrollSB( VclPtr<ScrollBar>::Create(this, WB_VERT) )
, mbRecalculateFont(true)
, mbUpdateForeground(true)
@@ -80,6 +88,7 @@ void SvxShowCharSet::init()
SetStyle(GetStyle() | WB_CLIPCHILDREN);
aVscrollSB->SetScrollHdl( LINK( this, SvxShowCharSet, VscrollHdl ) );
aVscrollSB->EnableDrag();
+ getFavCharacterList();
// other settings like aVscroll depend on selected font => see RecalculateFont
bDrag = false;
@@ -155,6 +164,16 @@ void SvxShowCharSet::MouseButtonDown( const MouseEvent& rMEvt )
if ( !(rMEvt.GetClicks() % 2) )
aDoubleClkHdl.Call( this );
}
+
+ if(rMEvt.IsRight())
+ {
+ Point aPosition (rMEvt.GetPosPixel());
+ maPosition = aPosition;
+ int nIndex = PixelToMapIndex( rMEvt.GetPosPixel() );
+ // Fire the focus event
+ SelectIndex( nIndex, true);
+ createContextMenu();
+ }
}
@@ -206,6 +225,186 @@ sal_uInt16 SvxShowCharSet::GetRowPos(sal_uInt16 _nPos)
return _nPos / COLUMN_COUNT ;
}
+void SvxShowCharSet::getFavCharacterList()
+{
+ maFavCharList.clear();
+ maFavCharFontList.clear();
+ //retrieve recent character list
+ css::uno::Sequence< OUString > rFavCharList( officecfg::Office::Common::FavoriteCharacters::FavoriteCharacterList::get() );
+ for (int i = 0; i < rFavCharList.getLength(); ++i)
+ {
+ maFavCharList.push_back(rFavCharList[i]);
+ }
+
+ //retrieve recent character font list
+ css::uno::Sequence< OUString > rFavCharFontList( officecfg::Office::Common::FavoriteCharacters::FavoriteCharacterFontList::get() );
+ for (int i = 0; i < rFavCharFontList.getLength(); ++i)
+ {
+ maFavCharFontList.push_back(rFavCharFontList[i]);
+ }
+}
+
+bool SvxShowCharSet::isFavChar(const OUString& sTitle, const OUString& rFont)
+{
+ auto itChar = std::find_if(maFavCharList.begin(),
+ maFavCharList.end(),
+ [sTitle] (const OUString & a) { return a == sTitle; });
+
+ auto itChar2 = std::find_if(maFavCharFontList.begin(),
+ maFavCharFontList.end(),
+ [rFont] (const OUString & a) { return a == rFont; });
+
+ // if Fav char to be added is already in list, return true
+ if( itChar != maFavCharList.end() && itChar2 != maFavCharFontList.end() )
+ return true;
+ else
+ return false;
+}
+
+void SvxShowCharSet::createContextMenu()
+{
+ ScopedVclPtrInstance<PopupMenu> pItemMenu;
+ pItemMenu->InsertItem(0,SvxResId(RID_INSERT));
+ sal_UCS4 cChar = GetSelectCharacter();
+ OUString aOUStr( &cChar, 1 );
+ if(!isFavChar(aOUStr, GetFont().GetFamilyName()))
+ {
+ if(maFavCharList.size() < 16)
+ pItemMenu->InsertItem(1,SvxResId(RID_ADD_TO_FAVORITES));
+ }
+ else
+ pItemMenu->InsertItem(1,SvxResId(RID_REMOVE_FAVORITES));
+
+ pItemMenu->InsertItem(2, SvxResId(RID_COPY_CLIPBOARD ));
+ pItemMenu->SetSelectHdl(LINK(this, SvxShowCharSet, ContextMenuSelectHdl));
+ pItemMenu->Execute(this, tools::Rectangle(maPosition,Size(1,1)), PopupMenuFlags::ExecuteDown);
+ GrabFocus();
+ Invalidate();
+}
+
+
+IMPL_LINK(SvxShowCharSet, ContextMenuSelectHdl, Menu*, pMenu, bool)
+{
+ sal_uInt16 nMenuId = pMenu->GetCurItemId();
+ sal_UCS4 cChar = GetSelectCharacter();
+ OUString aOUStr( &cChar, 1 );
+
+ switch(nMenuId)
+ {
+ case 0:
+ aDoubleClkHdl.Call(this);
+ break;
+ case 1:
+ updateFavCharacterList(aOUStr, GetFont().GetFamilyName());
+ aFavClickHdl.Call(this);
+ break;
+ case 2:
+ CopyToClipboard(aOUStr);
+ break;
+ default:
+ break;
+ }
+ return false;
+}
+
+
+void SvxShowCharSet::CopyToClipboard(const OUString& aOUStr)
+{
+ css::uno::Reference<css::datatransfer::clipboard::XClipboard> rxClipboard(GetClipboard());
+
+ if ( rxClipboard.is() )
+ {
+ TETextDataObject* pDataObj = new TETextDataObject( aOUStr );
+
+ try
+ {
+ rxClipboard->setContents( pDataObj, nullptr );
+
+ css::uno::Reference< css::datatransfer::clipboard::XFlushableClipboard > xFlushableClipboard( rxClipboard, css::uno::UNO_QUERY );
+ if( xFlushableClipboard.is() )
+ xFlushableClipboard->flushClipboard();
+ }
+ catch( const css::uno::Exception& )
+ {
+ }
+ }
+}
+
+
+void SvxShowCharSet::updateFavCharacterList(const OUString& sTitle, const OUString& rFont)
+{
+ if(isFavChar(sTitle, rFont))
+ {
+ auto itChar = std::find_if(maFavCharList.begin(),
+ maFavCharList.end(),
+ [sTitle] (const OUString & a) { return a == sTitle; });
+
+ auto itChar2 = std::find_if(maFavCharFontList.begin(),
+ maFavCharFontList.end(),
+ [rFont] (const OUString & a) { return a == rFont; });
+
+ // if Fav char to be added is already in list, remove it
+ if( itChar != maFavCharList.end() && itChar2 != maFavCharFontList.end() )
+ {
+ maFavCharList.erase( itChar );
+ maFavCharFontList.erase( itChar2);
+ }
+
+ css::uno::Sequence< OUString > aFavCharList(maFavCharList.size());
+ css::uno::Sequence< OUString > aFavCharFontList(maFavCharFontList.size());
+
+ for (size_t i = 0; i < maFavCharList.size(); ++i)
+ {
+ aFavCharList[i] = maFavCharList[i];
+ aFavCharFontList[i] = maFavCharFontList[i];
+ }
+
+ 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();
+ return;
+ }
+
+ auto itChar = std::find_if(maFavCharList.begin(),
+ maFavCharList.end(),
+ [sTitle] (const OUString & a) { return a == sTitle; });
+
+ auto itChar2 = std::find_if(maFavCharFontList.begin(),
+ maFavCharFontList.end(),
+ [rFont] (const OUString & a) { return a == rFont; });
+
+ // if Fav char to be added is already in list, remove it
+ if( itChar != maFavCharList.end() && itChar2 != maFavCharFontList.end() )
+ {
+ maFavCharList.erase( itChar );
+ maFavCharFontList.erase( itChar2);
+ }
+
+ if (maFavCharList.size() == 16)
+ {
+ maFavCharList.pop_back();
+ maFavCharFontList.pop_back();
+ }
+
+ maFavCharList.push_back(sTitle);
+ maFavCharFontList.push_back(rFont);
+
+ css::uno::Sequence< OUString > aFavCharList(maFavCharList.size());
+ css::uno::Sequence< OUString > aFavCharFontList(maFavCharFontList.size());
+
+ for (size_t i = 0; i < maFavCharList.size(); ++i)
+ {
+ aFavCharList[i] = maFavCharList[i];
+ aFavCharFontList[i] = maFavCharFontList[i];
+ }
+
+ 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();
+}
+
sal_uInt16 SvxShowCharSet::GetColumnPos(sal_uInt16 _nPos)
{
@@ -546,6 +745,7 @@ void SvxShowCharSet::RecalculateFont(vcl::RenderContext& rRenderContext)
aFont.SetTransparent(true);
rRenderContext.SetFont(aFont);
rRenderContext.GetFontCharMap(mxFontCharMap);
+ getFavCharacterList();
nX = aSize.Width() / COLUMN_COUNT;
nY = aSize.Height() / ROW_COUNT;
diff --git a/svx/source/dialog/searchcharmap.cxx b/svx/source/dialog/searchcharmap.cxx
index a65c709fb8d5..10e006333446 100644
--- a/svx/source/dialog/searchcharmap.cxx
+++ b/svx/source/dialog/searchcharmap.cxx
@@ -321,6 +321,7 @@ void SvxSearchCharSet::RecalculateFont(vcl::RenderContext& rRenderContext)
aFont.SetTransparent(true);
rRenderContext.SetFont(aFont);
rRenderContext.GetFontCharMap(mxFontCharMap);
+ getFavCharacterList();
nX = aSize.Width() / COLUMN_COUNT;
nY = aSize.Height() / ROW_COUNT;
diff --git a/vcl/source/edit/textview.cxx b/vcl/source/edit/textview.cxx
index 7c528430b151..7a32a8cf1878 100644
--- a/vcl/source/edit/textview.cxx
+++ b/vcl/source/edit/textview.cxx
@@ -62,31 +62,6 @@
#include <o3tl/make_unique.hxx>
-class TETextDataObject : public css::datatransfer::XTransferable,
- public ::cppu::OWeakObject
-
-{
-private:
- OUString maText;
- SvMemoryStream maHTMLStream;
-
-public:
- explicit TETextDataObject( const OUString& rText );
-
- OUString& GetText() { return maText; }
- SvMemoryStream& GetHTMLStream() { return maHTMLStream; }
-
- // css::uno::XInterface
- css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override;
- void SAL_CALL acquire() throw() override { OWeakObject::acquire(); }
- void SAL_CALL release() throw() override { OWeakObject::release(); }
-
- // css::datatransfer::XTransferable
- css::uno::Any SAL_CALL getTransferData( const css::datatransfer::DataFlavor& aFlavor ) override;
- css::uno::Sequence< css::datatransfer::DataFlavor > SAL_CALL getTransferDataFlavors( ) override;
- sal_Bool SAL_CALL isDataFlavorSupported( const css::datatransfer::DataFlavor& aFlavor ) override;
-};
-
TETextDataObject::TETextDataObject( const OUString& rText ) : maText( rText )
{
}
More information about the Libreoffice-commits
mailing list