nss: upgrade to release 3.73
[LibreOffice.git] / vcl / source / uipreviewer / previewer.cxx
blobab4d5f91d9b5554a83c86e6e3dca8ab8d2289ec8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #include <com/sun/star/lang/XComponent.hpp>
11 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
12 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
13 #include <com/sun/star/ucb/UniversalContentBroker.hpp>
14 #include <comphelper/processfactory.hxx>
15 #include <cppuhelper/bootstrap.hxx>
16 #include <osl/file.hxx>
17 #include <vcl/builder.hxx>
18 #include <vcl/toolkit/dialog.hxx>
19 #include <vcl/help.hxx>
20 #include <vcl/svapp.hxx>
21 #include <vcl/vclmain.hxx>
23 namespace {
25 class UIPreviewApp : public Application
27 public:
28 virtual void Init() override;
29 virtual int Main() override;
34 using namespace com::sun::star;
36 void UIPreviewApp::Init()
38 uno::Reference<uno::XComponentContext> xContext =
39 cppu::defaultBootstrap_InitialComponentContext();
40 uno::Reference<lang::XMultiComponentFactory> xFactory =
41 xContext->getServiceManager();
42 uno::Reference<lang::XMultiServiceFactory> xSFactory(xFactory, uno::UNO_QUERY_THROW);
43 comphelper::setProcessServiceFactory(xSFactory);
45 // Create UCB (for backwards compatibility, in case some code still uses
46 // plain createInstance w/o args directly to obtain an instance):
47 ::ucb::UniversalContentBroker::create(
48 comphelper::getProcessComponentContext() );
51 int UIPreviewApp::Main()
53 std::vector<OUString> uifiles;
54 for (sal_uInt16 i = 0; i < GetCommandLineParamCount(); ++i)
56 OUString aFileUrl;
57 osl::File::getFileURLFromSystemPath(GetCommandLineParam(i), aFileUrl);
58 uifiles.push_back(aFileUrl);
61 if (uifiles.empty())
63 fprintf(stderr, "Usage: ui-previewer file.ui\n");
64 return EXIT_FAILURE;
67 // turn on tooltips
68 Help::EnableQuickHelp();
70 int nRet = EXIT_SUCCESS;
72 try
74 VclPtrInstance<Dialog> pDialog(nullptr, WB_STDDIALOG | WB_SIZEABLE, Dialog::InitFlag::NoParent);
76 VclBuilder aBuilder(pDialog, OUString(), uifiles[0]);
77 vcl::Window *pRoot = aBuilder.get_widget_root();
78 Dialog *pRealDialog = dynamic_cast<Dialog*>(pRoot);
80 if (!pRealDialog)
81 pRealDialog = pDialog;
83 pRealDialog->SetText("LibreOffice ui-previewer");
84 pRealDialog->SetStyle(pDialog->GetStyle()|WB_CLOSEABLE);
86 Force a new StateChangedType::InitShow for the edge case where pRoot
87 is not a dialog or contents of a dialog, but instead a visible floating window
88 which may have had initshow already done before it was given children
90 pRoot->Hide();
91 pRoot->Show();
92 pRealDialog->Execute();
95 pDialog.disposeAndClear();
97 catch (const uno::Exception &e)
99 fprintf(stderr, "fatal error: %s\n", OUStringToOString(e.Message, osl_getThreadTextEncoding()).getStr());
100 nRet = EXIT_FAILURE;
102 catch (const std::exception &e)
104 fprintf(stderr, "fatal error: %s\n", e.what());
105 nRet = EXIT_FAILURE;
108 return nRet;
111 void vclmain::createApplication()
113 static UIPreviewApp aApp;
116 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */