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>
18 #include <i18nlangtag/mslangid.hxx>
19 #include <unotools/configmgr.hxx>
21 #include <vcl/svapp.hxx>
22 
23 #include "isheadless.hxx"
24 #include "setupvcl.hxx"
25 
26 namespace {
27 
28 struct 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):
36 IMPL_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 
73 void 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 setConfiguredSystemUILanguage(LanguageType nLang)
static void storeConfigItems()
static void setConfiguredSystemLanguage(LanguageType nLang)
LanguageType getLanguageType(bool bResolveSystem=true) const
OOO_DLLPUBLIC_TEST_SETUPVCL void setUpVcl(bool forceHeadless=false)
Definition: setupvcl.cxx:73
IMPL_STATIC_LINK_NOARG(SwGlobalTree, ShowFrameHdl, void *, void)
void SetLocaleConfigString(const OUString &rStr)
sal_uInt32 tag
VCL_DLLPUBLIC bool InitVCL()
bool isHeadless()
Definition: isheadless.hxx:20
void SetUILocaleConfigString(const OUString &rStr)
void setProcessServiceFactory(const Reference< XMultiServiceFactory > &xSMgr)
static void setDeInitHook(Link< LinkParamNone *, void > const &hook)
tuple config
Reference< XComponentContext > getProcessComponentContext()
static void EnableHeadlessMode(bool dialogsAreFatal)
void dispose()