25#include <officecfg/Office/Common.hxx>
26#include <officecfg/Setup.hxx>
35#include <com/sun/star/frame/FrameSearchFlag.hpp>
36#include <com/sun/star/frame/ModuleManager.hpp>
37#include <com/sun/star/frame/XFramesSupplier.hpp>
38#include <com/sun/star/frame/Desktop.hpp>
47 return "com.sun.star.comp.framework.HelpOnStartup";
69 m_sLocale = officecfg::Setup::L10N::ooLocale::get();
72 m_sSystem = officecfg::Office::Common::Help::System::get();
76 css::uno::Reference< css::lang::XComponent > xComponent;
79 xComponent->addEventListener(
static_cast< css::lang::XEventListener*
>(
this));
81 m_xDesktop->addEventListener(
static_cast< css::lang::XEventListener*
>(
this));
82 xComponent.set(
m_xConfig, css::uno::UNO_QUERY);
84 xComponent->addEventListener(
static_cast< css::lang::XEventListener*
>(
this));
100 if (sModule.isEmpty())
101 return css::uno::Any();
109 bool bShowIt =
false;
112 if (sCurrentHelpURL.isEmpty())
115 else if (bCurrentHelpURLIsAnyDefaultURL)
122 if (!sModuleDependentHelpURL.isEmpty())
128 pHelp->
Start(sModuleDependentHelpURL);
132 return css::uno::Any();
155 if (sEnvType !=
"DOCUMENTEVENT")
158 css::uno::Reference< css::frame::XModel > xDoc = lEnvironment.
getUnpackedValueOrDefault(
"Model", css::uno::Reference< css::frame::XModel >());
165 css::uno::Reference< css::frame::XDesktop > xDesktopCheck;
166 css::uno::Reference< css::frame::XFrame >
xFrame;
167 css::uno::Reference< css::frame::XController >
xController = xDoc->getCurrentController();
171 xDesktopCheck.set(
xFrame->getCreator(), css::uno::UNO_QUERY);
172 if (!xDesktopCheck.is())
178 std::unique_lock aLock(
m_mutex);
179 css::uno::Reference< css::frame::XModuleManager2 > xModuleManager =
m_xModuleManager;
186 sModuleId = xModuleManager->identify(xDoc);
188 catch(
const css::uno::RuntimeException&)
190 catch(
const css::uno::Exception&)
191 { sModuleId.clear(); }
199 std::unique_lock aLock(
m_mutex);
200 css::uno::Reference< css::frame::XDesktop2 > xDesktop =
m_xDesktop;
207 css::uno::Reference< css::frame::XFrame > xHelp = xDesktop->findFrame(
SPECIALTARGET_HELPTASK, css::frame::FrameSearchFlag::CHILDREN);
211 OUString sCurrentHelpURL;
214 css::uno::Reference< css::frame::XFramesSupplier > xHelpRoot (xHelp , css::uno::UNO_QUERY_THROW);
215 css::uno::Reference< css::container::XIndexAccess > xHelpChildren(xHelpRoot->getFrames(), css::uno::UNO_QUERY_THROW);
217 css::uno::Reference< css::frame::XFrame > xHelpChild;
218 css::uno::Reference< css::frame::XController > xHelpView;
219 css::uno::Reference< css::frame::XModel > xHelpContent;
221 xHelpChildren->getByIndex(0) >>= xHelpChild;
223 xHelpView = xHelpChild->getController();
225 xHelpContent = xHelpView->getModel();
226 if (xHelpContent.is())
227 sCurrentHelpURL = xHelpContent->getURL();
229 catch(
const css::uno::RuntimeException&)
231 catch(
const css::uno::Exception&)
232 { sCurrentHelpURL.clear(); }
234 return sCurrentHelpURL;
239 if (sHelpURL.empty())
243 std::unique_lock aLock(
m_mutex);
244 css::uno::Reference< css::container::XNameAccess > xConfig =
m_xConfig;
254 const css::uno::Sequence< OUString > lModules = xConfig->getElementNames();
255 const OUString* pModules = lModules.getConstArray();
256 ::sal_Int32 c = lModules.getLength();
263 css::uno::Reference< css::container::XNameAccess > xModuleConfig;
264 xConfig->getByName(pModules[
i]) >>= xModuleConfig;
265 if (!xModuleConfig.is())
268 OUString sHelpBaseURL;
269 xModuleConfig->getByName(
"ooSetupFactoryHelpBaseURL") >>= sHelpBaseURL;
271 if (sHelpURL == sHelpURLForModule)
274 catch(
const css::uno::RuntimeException&)
276 catch(
const css::uno::Exception&)
286 std::unique_lock aLock(
m_mutex);
287 css::uno::Reference< css::container::XNameAccess > xConfig =
m_xConfig;
297 css::uno::Reference< css::container::XNameAccess > xModuleConfig;
299 xConfig->getByName(sModule) >>= xModuleConfig;
301 bool bHelpEnabled =
false;
302 if (xModuleConfig.is())
303 xModuleConfig->getByName(
"ooSetupFactoryHelpOnOpen") >>= bHelpEnabled;
307 OUString sHelpBaseURL;
308 xModuleConfig->getByName(
"ooSetupFactoryHelpBaseURL") >>= sHelpBaseURL;
312 catch(
const css::uno::RuntimeException&)
314 catch(
const css::uno::Exception&)
315 { sHelpURL.clear(); }
321 std::u16string_view sLocale ,
322 std::u16string_view sSystem )
324 return OUString::Concat(sBaseURL) +
"?Language=" + sLocale +
"&System=" + sSystem;
329extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
331 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any>
const& )
constexpr OUStringLiteral sServiceName
virtual bool Start(const OUString &rHelpId, weld::Widget *pWidget=nullptr)
TValueType getUnpackedValueOrDefault(const OUString &sKey, const TValueType &aDefault) const
implements a job component, which handle the special feature to show a suitable help page for every (...
HelpOnStartup(css::uno::Reference< css::uno::XComponentContext > xContext)
create new instance of this class.
css::uno::Reference< css::frame::XDesktop2 > m_xDesktop
is needed to locate a might open help frame.
static OUString ist_createHelpURL(std::u16string_view sBaseURL, std::u16string_view sLocale, std::u16string_view sSystem)
create a help URL for the given parameters.
OUString its_checkIfHelpEnabledAndGetURL(const OUString &sModule)
checks, if the help module should be shown automatically for the currently opened office module.
virtual void SAL_CALL disposing(const css::lang::EventObject &aEvent) override
virtual OUString SAL_CALL getImplementationName() override
OUString its_getCurrentHelpURL()
tries to locate the open help module and return the url of the currently shown help content.
OUString m_sSystem
knows the current operating system of this office session, which is needed to build complete help URL...
bool its_isHelpUrlADefaultOne(std::u16string_view sHelpURL)
checks if the given help url match to a default help url of any office module.
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
css::uno::Reference< css::frame::XModuleManager2 > m_xModuleManager
such module manager is used to classify new opened documents.
OUString m_sLocale
knows the current locale of this office session, which is needed to build complete help URLs.
virtual css::uno::Any SAL_CALL execute(const css::uno::Sequence< css::beans::NamedValue > &lArguments) override
virtual ~HelpOnStartup() override
does nothing real ...
virtual sal_Bool SAL_CALL supportsService(const OUString &sServiceName) override
css::uno::Reference< css::uno::XComponentContext > m_xContext
reference to a uno service manager.
css::uno::Reference< css::container::XNameAccess > m_xConfig
provides read access to the underlying configuration.
OUString its_getModuleIdFromEnv(const css::uno::Sequence< css::beans::NamedValue > &lArguments)
analyze the given job arguments, try to locate a model reference and try to classify this model.
css::uno::Reference< css::uno::XComponentContext > m_xContext
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * framework_HelpOnStartup_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
constexpr OUStringLiteral SERVICENAME_JOB
constexpr OUStringLiteral SPECIALTARGET_HELPTASK
Reference< XController > xController
Reference< XFrame > xFrame