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 <comphelper/processfactory.hxx>
11 #include <cppuhelper/bootstrap.hxx>
12 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
13 #include <com/sun/star/lang/XInitialization.hpp>
14 #include <com/sun/star/registry/XSimpleRegistry.hpp>
15 #include <com/sun/star/ucb/UniversalContentBroker.hpp>
17 #include <vcl/vclmain.hxx>
18 #include <vcl/layout.hxx>
19 #include <vcl/gdimtf.hxx>
20 #include <vcl/wmf.hxx>
22 #include <tools/diagnose_ex.h>
23 #include <tools/urlobj.hxx>
24 #include <tools/stream.hxx>
25 #include <tools/vcompat.hxx>
26 #include <vcl/svapp.hxx>
27 #include <vcl/wrkwin.hxx>
28 #include <vcl/virdev.hxx>
29 #include <sal/log.hxx>
37 class DemoMtfWin
: public WorkWindow
42 explicit DemoMtfWin(const OUString
& rFileName
)
43 : WorkWindow(nullptr, WB_APP
| WB_STDWORK
)
45 SvFileStream
aFileStream(rFileName
, StreamMode::READ
);
47 if (aFileStream
.IsOpen())
49 ReadWindowMetafile(aFileStream
, maMtf
);
53 Application::Abort("Can't read metafile");
57 virtual void Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
) override
;
62 void DemoMtfWin::Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
)
64 maMtf
.Play(*GetOutDev(), maMtf
.GetActionSize());
66 WorkWindow::Paint(rRenderContext
, rRect
);
71 class DemoMtfApp
: public Application
73 VclPtr
<DemoMtfWin
> mpWin
;
76 static void showHelp()
78 fprintf(stderr
, "Usage: mtfdemo --help | FILE\n");
79 fprintf(stderr
, "A VCL test app that displays Windows metafiles\n");
90 virtual int Main() override
94 mpWin
= VclPtr
<DemoMtfWin
>::Create(maFileName
);
95 mpWin
->SetText("Display metafile");
99 Application::Execute();
101 catch (const css::uno::Exception
&)
103 TOOLS_WARN_EXCEPTION("vcl.app", "Fatal");
106 catch (const std::exception
& e
)
108 SAL_WARN("vcl.app", "Fatal: " << e
.what());
115 uno::Reference
<lang::XMultiServiceFactory
> xMSF
;
120 const sal_uInt16 nCmdParams
= GetCommandLineParamCount();
126 OUString aArg
= GetCommandLineParam(0);
128 if (aArg
== "--help" || aArg
== "-h")
134 uno::Reference
<uno::XComponentContext
> xComponentContext
135 = ::cppu::defaultBootstrap_InitialComponentContext();
136 xMSF
.set(xComponentContext
->getServiceManager(), uno::UNO_QUERY
);
138 Application::Abort("Bootstrap failure - no service manager");
140 ::comphelper::setProcessServiceFactory(xMSF
);
142 catch (const uno::Exception
&e
)
144 Application::Abort("Bootstrap exception " + e
.Message
);
148 void DeInit() override
150 uno::Reference
< lang::XComponent
>(
151 comphelper::getProcessComponentContext(),
152 uno::UNO_QUERY_THROW
)-> dispose();
153 ::comphelper::setProcessServiceFactory(nullptr);
160 void vclmain::createApplication()
162 static DemoMtfApp aApp
;
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */