diff options
author | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2016-10-20 10:49:24 +0200 |
---|---|---|
committer | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2016-10-20 12:48:43 +0200 |
commit | f0006e79c4112b06b65c098722729b9a3f3301c7 (patch) | |
tree | ac7dcac47f7c8da208484f91c55a1abc11b742be /vcl | |
parent | 168463ed0537a5a9737aa5226657af1e263d0036 (diff) |
Handle link click directly in FixedHyperlink
Change-Id: I5b5f0648b6e6432b0928351a17d285df8c9da811
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/source/control/fixedhyper.cxx | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/vcl/source/control/fixedhyper.cxx b/vcl/source/control/fixedhyper.cxx index 7f940dd203cb..51a12f661cf9 100644 --- a/vcl/source/control/fixedhyper.cxx +++ b/vcl/source/control/fixedhyper.cxx @@ -19,6 +19,16 @@ #include <vcl/fixedhyper.hxx> #include <vcl/svapp.hxx> +#include <vcl/layout.hxx> +#include <comphelper/anytostring.hxx> +#include <comphelper/processfactory.hxx> +#include <cppuhelper/exc_hlp.hxx> + +#include <com/sun/star/system/XSystemShellExecute.hpp> +#include <com/sun/star/system/SystemShellExecuteFlags.hpp> +#include <com/sun/star/system/SystemShellExecute.hpp> + +using namespace css; FixedHyperlink::FixedHyperlink(vcl::Window* pParent, WinBits nWinStyle) : FixedText(pParent, nWinStyle) @@ -40,6 +50,8 @@ void FixedHyperlink::Initialize() SetControlForeground( Application::GetSettings().GetStyleSettings().GetLinkColor() ); // calculates text len m_nTextLen = GetCtrlTextWidth( GetText() ); + + SetClickHdl(LINK(this, FixedHyperlink, HandleClick)); } bool FixedHyperlink::ImplIsOverText(Point aPosition) @@ -137,4 +149,27 @@ bool FixedHyperlink::set_property(const OString &rKey, const OString &rValue) return true; } +IMPL_LINK(FixedHyperlink, HandleClick, FixedHyperlink&, rHyperlink, void) +{ + if ( rHyperlink.m_sURL.isEmpty() ) // Nothing to do, when the URL is empty + return; + + try + { + uno::Reference< system::XSystemShellExecute > xSystemShellExecute( + system::SystemShellExecute::create(comphelper::getProcessComponentContext())); + //throws css::lang::IllegalArgumentException, css::system::SystemShellExecuteException + xSystemShellExecute->execute( rHyperlink.m_sURL, OUString(), system::SystemShellExecuteFlags::URIS_ONLY ); + } + catch ( const uno::Exception& ) + { + uno::Any exc(cppu::getCaughtException()); + OUString msg(comphelper::anyToString(exc)); + const SolarMutexGuard guard; + ScopedVclPtrInstance< MessageDialog > aErrorBox(nullptr, msg); + aErrorBox->SetText( rHyperlink.GetText() ); + aErrorBox->Execute(); + } +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |