LibreOffice Module test (master) 1
setupvcl.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9
10#include <sal/config.h>
11
12#include <com/sun/star/configuration/theDefaultProvider.hpp>
13#include <com/sun/star/lang/XComponent.hpp>
14#include <com/sun/star/util/XFlushable.hpp>
15#include <com/sun/star/frame/Desktop.hpp>
21#include <vcl/svapp.hxx>
22
23#include "isheadless.hxx"
24#include "setupvcl.hxx"
25
26namespace {
27
28struct Hook { // LINK only works as a member of a class...
29 DECL_STATIC_LINK(Hook, deinitHook, LinkParamNone *, void);
30};
31
32// HACK so that defaultBootstrap_InitialComponentContext (in
33// unobootstrapprotector) is called before InitVCL (below), but component
34// context is disposed (redundantly again in unobootstrapprotector) from within
35// DeInitVCL (cf. Desktop::DeInit, desktop/source/app/app.cxx):
36IMPL_STATIC_LINK_NOARG(Hook, deinitHook, LinkParamNone *, void) {
37 css::uno::Reference<css::uno::XComponentContext> context;
38 try {
40 } catch (css::uno::RuntimeException &) {}
41
42 if (!context)
43 return;
44
45 css::uno::Reference<css::lang::XMultiServiceFactory> config;
46 try {
47 config = css::configuration::theDefaultProvider::get(context);
48 } catch (css::uno::DeploymentException &) {}
49 if (config) {
51 css::uno::Reference<css::util::XFlushable>(
52 config, css::uno::UNO_QUERY_THROW)->flush();
53 }
54
55 // the desktop has to be terminate() before it can be dispose()
56 css::uno::Reference<css::frame::XDesktop> xDesktop;
57 try {
58 xDesktop = css::frame::Desktop::create(comphelper::getProcessComponentContext());
59 } catch (css::uno::DeploymentException &) {}
60 if (xDesktop)
61 try {
62 xDesktop->terminate();
63 } catch (css::uno::DeploymentException &) {}
64
65 css::uno::Reference<css::lang::XComponent>(
66 context, css::uno::UNO_QUERY_THROW)->dispose();
67
69}
70
71}
72
73void test::setUpVcl(bool const forceHeadless) {
74 // Force locale (and resource files loaded):
75 OUString locale;
76 if (getenv("LO_TEST_LOCALE") != nullptr)
77 locale = OUString::fromUtf8(getenv("LO_TEST_LOCALE"));
78 else
79 locale = "en-US";
80
81 SvtSysLocaleOptions localOptions;
82 localOptions.SetLocaleConfigString(locale);
83 localOptions.SetUILocaleConfigString(locale);
84 LanguageTag tag(locale);
87 InitVCL();
88 if (forceHeadless || isHeadless()) {
90 }
91 Application::setDeInitHook(LINK(nullptr, Hook, deinitHook));
92}
93
94/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
static void setDeInitHook(Link< LinkParamNone *, void > const &hook)
static void EnableHeadlessMode(bool dialogsAreFatal)
LanguageType getLanguageType(bool bResolveSystem=true) const
static void setConfiguredSystemLanguage(LanguageType nLang)
static void setConfiguredSystemUILanguage(LanguageType nLang)
void SetLocaleConfigString(const OUString &rStr)
void SetUILocaleConfigString(const OUString &rStr)
static void storeConfigItems()
void setProcessServiceFactory(const Reference< XMultiServiceFactory > &xSMgr)
Reference< XComponentContext > getProcessComponentContext()
config
bool isHeadless()
Definition: isheadless.hxx:20
OOO_DLLPUBLIC_TEST_SETUPVCL void setUpVcl(bool forceHeadless=false)
Definition: setupvcl.cxx:73
VCL_DLLPUBLIC bool InitVCL()
IMPL_STATIC_LINK_NOARG(SwSyncBtnDlg, BtnHdl, weld::Button &, void)