summaryrefslogtreecommitdiff
path: root/sfx2/source/menu
diff options
context:
space:
mode:
authorThomas Lange [tl] <tl@openoffice.org>2010-02-05 13:45:10 +0100
committerThomas Lange [tl] <tl@openoffice.org>2010-02-05 13:45:10 +0100
commit9a53424f5d2a1ee60795c1cd1daeda47615072f8 (patch)
tree8fc32b333de72dc7e201b95ca270a1d5f9e1e1c4 /sfx2/source/menu
parentbc248321a604ea7849b1b036e3b331a826a74de2 (diff)
#161586# allowing for thesaurus vendor images
Diffstat (limited to 'sfx2/source/menu')
-rwxr-xr-x[-rw-r--r--]sfx2/source/menu/mnumgr.cxx38
-rwxr-xr-x[-rw-r--r--]sfx2/source/menu/thessubmenu.cxx105
-rwxr-xr-xsfx2/source/menu/thessubmenu.hxx20
3 files changed, 136 insertions, 27 deletions
diff --git a/sfx2/source/menu/mnumgr.cxx b/sfx2/source/menu/mnumgr.cxx
index 4f371fe6aa..a87d93c786 100644..100755
--- a/sfx2/source/menu/mnumgr.cxx
+++ b/sfx2/source/menu/mnumgr.cxx
@@ -30,8 +30,10 @@
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sfx2.hxx"
+
#include <com/sun/star/embed/VerbDescriptor.hpp>
#include <com/sun/star/embed/VerbAttributes.hpp>
+#include <com/sun/star/container/XNamed.hpp>
#ifdef SOLARIS
// HACK: prevent conflict between STLPORT and Workshop headers on Solaris 8
@@ -53,10 +55,15 @@
#include <framework/addonmenu.hxx>
#include <comphelper/processfactory.hxx>
#include <unotools/ucbstreamhelper.hxx>
+#include <unotools/lingucfg.hxx>
#include <tools/urlobj.hxx>
#include <unotools/pathoptions.hxx>
#include <svl/stritem.hxx>
#include <toolkit/helper/vclunohelper.hxx>
+#include <osl/file.hxx>
+#include <vcl/graph.hxx>
+#include <svtools/filter.hxx>
+#include <svx/impgrf.hxx>
#include <sfx2/mnumgr.hxx>
@@ -177,6 +184,24 @@ void InsertVerbs_Impl( SfxBindings* pBindings, const com::sun::star::uno::Sequen
//--------------------------------------------------------------------
+
+static Image lcl_GetImageFromPngUrl( const ::rtl::OUString &rFileUrl )
+{
+ Image aRes;
+
+ ::rtl::OUString aTmp;
+ osl::FileBase::getSystemPathFromFileURL( rFileUrl, aTmp );
+
+ Graphic aGraphic;
+ const String aFilterName( RTL_CONSTASCII_USTRINGPARAM( IMP_PNG ) );
+ if( GRFILTER_OK == lcl_LoadGraphic( aTmp, aFilterName, aGraphic ) )
+ {
+ aRes = Image( aGraphic.GetBitmapEx() );
+ }
+ return aRes;
+}
+
+
PopupMenu* InsertThesaurusSubmenu_Impl( SfxBindings* pBindings, Menu* pSVMenu )
{
//
@@ -209,15 +234,28 @@ PopupMenu* InsertThesaurusSubmenu_Impl( SfxBindings* pBindings, Menu* pSVMenu )
const size_t nNumSynonyms = aSynonyms.size();
if (nNumSynonyms > 0)
{
+ SvtLinguConfig aCfg;
+ const bool bHC = Application::GetSettings().GetStyleSettings().GetHighContrastMode();
+
+ Image aImage;
+ String sThesImplName( aHelper.GetThesImplName( aLocale ) );
+ ::rtl::OUString aSynonymsImageUrl( aCfg.GetSynonymsContextImage( sThesImplName, bHC ) );
+ if (sThesImplName.Len() > 0 && aSynonymsImageUrl.getLength() > 0)
+ aImage = Image( lcl_GetImageFromPngUrl( aSynonymsImageUrl ) );
+
for (USHORT i = 0; (size_t)i < nNumSynonyms; ++i)
{
//! item ids should start with values > 0, since 0 has special meaning
const USHORT nId = i + 1;
+
String aItemText( GetThesaurusReplaceText_Impl( aSynonyms[i] ) );
pThesSubMenu->InsertItem( nId, aItemText );
::rtl::OUString aCmd( ::rtl::OUString::createFromAscii( ".uno:ThesaurusFromContext?WordReplace:string=" ) );
aCmd += aItemText;
pThesSubMenu->SetItemCommand( nId, aCmd );
+
+ if (aSynonymsImageUrl.getLength() > 0)
+ pThesSubMenu->SetItemImage( nId, aImage );
}
}
else // nNumSynonyms == 0
diff --git a/sfx2/source/menu/thessubmenu.cxx b/sfx2/source/menu/thessubmenu.cxx
index a4127a3015..a9f8415d00 100644..100755
--- a/sfx2/source/menu/thessubmenu.cxx
+++ b/sfx2/source/menu/thessubmenu.cxx
@@ -34,6 +34,7 @@
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/linguistic2/XThesaurus.hpp>
#include <com/sun/star/linguistic2/XMeaning.hpp>
+#include <com/sun/star/linguistic2/XLinguServiceManager.hpp>
#include <comphelper/processfactory.hxx>
#include <svl/stritem.hxx>
@@ -102,7 +103,8 @@ SfxThesSubMenuControl::SfxThesSubMenuControl( USHORT nSlotId, Menu &rMenu, SfxBi
{
rMenu.SetPopupMenu(nSlotId, pMenu);
pMenu->SetSelectHdl(LINK(this, SfxThesSubMenuControl, MenuSelect));
- FillMenu();
+ pMenu->Clear();
+ rParent.EnableItem( GetId(), FALSE );
}
@@ -113,27 +115,7 @@ SfxThesSubMenuControl::~SfxThesSubMenuControl()
/*
- Fuellt das Menu mit den aktuellen Verben aus der ViewShell.
- */
-void SfxThesSubMenuControl::FillMenu()
-{
- pMenu->Clear();
- pMenu->SetMenuFlags(MENU_FLAG_NOAUTOMNEMONICS);
- SfxViewShell *pView = GetBindings().GetDispatcher()->GetFrame()->GetViewShell();
- if (pView)
- {
- pMenu->InsertItem( 1, String::CreateFromAscii("bla blub") );
-
- }
-
- rParent.EnableItem( GetId(), (BOOL)pMenu->GetItemCount() );
-}
-
-
-/*
Statusbenachrichtigung;
- fuellt gfs. das Menu mit den aktuellen Verben aus der ViewShell.
- der DocumentShell.
Ist die Funktionalit"at disabled, wird der entsprechende
Menueeintrag im Parentmenu disabled, andernfalls wird er enabled.
*/
@@ -143,8 +125,6 @@ void SfxThesSubMenuControl::StateChanged(
const SfxPoolItem* /*pState*/ )
{
rParent.EnableItem(GetId(), SFX_ITEM_AVAILABLE == eState );
- if ( SFX_ITEM_AVAILABLE == eState )
- FillMenu();
}
@@ -199,9 +179,10 @@ SfxThesSubMenuHelper::SfxThesSubMenuHelper()
try
{
uno::Reference< lang::XMultiServiceFactory > xMSF( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
- m_xThesarus = uno::Reference< linguistic2::XThesaurus > ( xMSF->createInstance(
+ m_xLngMgr = uno::Reference< linguistic2::XLinguServiceManager >( xMSF->createInstance(
OUString( RTL_CONSTASCII_USTRINGPARAM(
- "com.sun.star.linguistic2.Thesaurus" ) ) ), uno::UNO_QUERY_THROW ) ;
+ "com.sun.star.linguistic2.LinguServiceManager" ))), uno::UNO_QUERY_THROW );
+ m_xThesarus = m_xLngMgr->getThesaurus();
}
catch (uno::Exception &e)
{
@@ -269,6 +250,80 @@ bool SfxThesSubMenuHelper::GetMeanings(
}
+String SfxThesSubMenuHelper::GetThesImplName( const lang::Locale &rLocale ) const
+{
+ String aRes;
+ DBG_ASSERT( m_xLngMgr.is(), "LinguServiceManager missing" );
+ if (m_xLngMgr.is())
+ {
+ uno::Sequence< OUString > aServiceNames = m_xLngMgr->getConfiguredServices(
+ OUString::createFromAscii("com.sun.star.linguistic2.Thesaurus"), rLocale );
+ // there should be at most one thesaurus configured for each language
+ DBG_ASSERT( aServiceNames.getLength() <= 1, "more than one thesaurus found. Should not be possible" );
+ if (aServiceNames.getLength() == 1)
+ aRes = aServiceNames[0];
+ }
+ return aRes;
+}
+
////////////////////////////////////////////////////////////
+//!! temporary implement locally:
+//!! once MBAs latest CWS is integrated this functions are available in svtools
+//!! under a slightly different name
+
+#include <sfx2/docfile.hxx>
+
+#define IMPGRF_INIKEY_ASLINK "ImportGraphicAsLink"
+#define IMPGRF_INIKEY_PREVIEW "ImportGraphicPreview"
+#define IMPGRF_CONFIGNAME String(DEFINE_CONST_UNICODE("ImportGraphicDialog"))
+
+GraphicFilter* lcl_GetGrfFilter()
+{
+ return GraphicFilter::GetGraphicFilter();
+}
+
+// -----------------------------------------------------------------------
+
+int lcl_LoadGraphic( const String &rPath, const String &rFilterName,
+ Graphic& rGraphic, GraphicFilter* pFilter,
+ USHORT* pDeterminedFormat )
+{
+ if ( !pFilter )
+ pFilter = ::lcl_GetGrfFilter();
+
+ const USHORT nFilter = rFilterName.Len() && pFilter->GetImportFormatCount()
+ ? pFilter->GetImportFormatNumber( rFilterName )
+ : GRFILTER_FORMAT_DONTKNOW;
+
+ SfxMedium* pMed = 0;
+
+ // dann teste mal auf File-Protokoll:
+ SvStream* pStream = NULL;
+ INetURLObject aURL( rPath );
+
+ if ( aURL.HasError() || INET_PROT_NOT_VALID == aURL.GetProtocol() )
+ {
+ aURL.SetSmartProtocol( INET_PROT_FILE );
+ aURL.SetSmartURL( rPath );
+ }
+ else if ( INET_PROT_FILE != aURL.GetProtocol() )
+ {
+ // z.Z. nur auf die aktuelle DocShell
+ pMed = new SfxMedium( rPath, STREAM_READ, TRUE );
+ pMed->DownLoad();
+ pStream = pMed->GetInStream();
+ }
+ int nRes = GRFILTER_OK;
+
+ if ( !pStream )
+ nRes = pFilter->ImportGraphic( rGraphic, aURL, nFilter, pDeterminedFormat );
+ else
+ nRes = pFilter->ImportGraphic( rGraphic, rPath, *pStream,
+ nFilter, pDeterminedFormat );
+ if ( pMed )
+ delete pMed;
+ return nRes;
+}
+
diff --git a/sfx2/source/menu/thessubmenu.hxx b/sfx2/source/menu/thessubmenu.hxx
index 109ba277f5..bfcbc7cccc 100755
--- a/sfx2/source/menu/thessubmenu.hxx
+++ b/sfx2/source/menu/thessubmenu.hxx
@@ -33,6 +33,7 @@
#define _THESSUBMENU_HXX_
#include <com/sun/star/linguistic2/XThesaurus.hpp>
+#include <com/sun/star/linguistic2/XLinguServiceManager.hpp>
#include <vcl/menu.hxx>
#include <sfx2/mnuitem.hxx>
@@ -55,7 +56,6 @@ class SfxThesSubMenuControl : public SfxMenuControl
Menu& rParent;
private:
- void FillMenu();
virtual void StateChanged( USHORT, SfxItemState, const SfxPoolItem* pState );
DECL_LINK( MenuSelect, Menu * );
@@ -72,7 +72,8 @@ public:
class SfxThesSubMenuHelper
{
- css::uno::Reference< css::linguistic2::XThesaurus > m_xThesarus;
+ css::uno::Reference< css::linguistic2::XLinguServiceManager > m_xLngMgr;
+ css::uno::Reference< css::linguistic2::XThesaurus > m_xThesarus;
private:
@@ -94,9 +95,24 @@ public:
// get the first nMax Synonym entries, even if different meanings need to be evaluated
bool GetMeanings( std::vector< ::rtl::OUString > & rSynonyms, const ::rtl::OUString & rWord, const css::lang::Locale & rLocale, sal_Int16 nMaxSynonms );
+
+ String GetThesImplName( const css::lang::Locale &rLocale ) const;
};
////////////////////////////////////////////////////////////
+
+
+#include <svx/impgrf.hxx>
+
+//!! temporary implemented locally:
+//!! once MBAs latest CWS is integrated this functions are available in svtools
+//!! under a slightly different name
+GraphicFilter* lcl_GetGrfFilter();
+int lcl_LoadGraphic( const String& rPath, const String& rFilter,
+ Graphic& rGraphic,
+ GraphicFilter* pFilter = NULL,
+ USHORT* pDeterminedFormat = NULL );
+
#endif