1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
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/dialog.hxx>
19 #include <vcl/help.hxx>
20 #include <vcl/svapp.hxx>
21 #include <vcl/vclmain.hxx>
23 class UIPreviewApp
: public Application
26 virtual void Init() override
;
27 virtual int Main() override
;
30 using namespace com::sun::star
;
32 void UIPreviewApp::Init()
34 uno::Reference
<uno::XComponentContext
> xContext
=
35 cppu::defaultBootstrap_InitialComponentContext();
36 uno::Reference
<lang::XMultiComponentFactory
> xFactory
=
37 xContext
->getServiceManager();
38 uno::Reference
<lang::XMultiServiceFactory
> xSFactory
=
39 uno::Reference
<lang::XMultiServiceFactory
> (xFactory
, uno::UNO_QUERY_THROW
);
40 comphelper::setProcessServiceFactory(xSFactory
);
42 // Create UCB (for backwards compatibility, in case some code still uses
43 // plain createInstance w/o args directly to obtain an instance):
44 ::ucb::UniversalContentBroker::create(
45 comphelper::getProcessComponentContext() );
48 int UIPreviewApp::Main()
50 std::vector
<OUString
> uifiles
;
51 for (sal_uInt16 i
= 0; i
< GetCommandLineParamCount(); ++i
)
54 osl::File::getFileURLFromSystemPath(GetCommandLineParam(i
), aFileUrl
);
55 uifiles
.push_back(aFileUrl
);
60 fprintf(stderr
, "Usage: ui-previewer file.ui\n");
65 Help::EnableQuickHelp();
67 int nRet
= EXIT_SUCCESS
;
71 VclPtrInstance
<Dialog
> pDialog(nullptr, WB_STDDIALOG
| WB_SIZEABLE
, Dialog::InitFlag::NoParent
);
73 VclBuilder
aBuilder(pDialog
, OUString(), uifiles
[0]);
74 vcl::Window
*pRoot
= aBuilder
.get_widget_root();
75 Dialog
*pRealDialog
= dynamic_cast<Dialog
*>(pRoot
);
78 pRealDialog
= pDialog
;
80 pRealDialog
->SetText("LibreOffice ui-previewer");
81 pRealDialog
->SetStyle(pDialog
->GetStyle()|WB_CLOSEABLE
);
83 Force a new StateChangedType::InitShow for the edge case where pRoot
84 is not a dialog or contents of a dialog, but instead a visible floating window
85 which may have had initshow already done before it was given children
89 pRealDialog
->Execute();
92 pDialog
.disposeAndClear();
94 catch (const uno::Exception
&e
)
96 fprintf(stderr
, "fatal error: %s\n", OUStringToOString(e
.Message
, osl_getThreadTextEncoding()).getStr());
99 catch (const std::exception
&e
)
101 fprintf(stderr
, "fatal error: %s\n", e
.what());
108 void vclmain::createApplication()
110 static UIPreviewApp aApp
;
113 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */