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 <comphelper/random.hxx>
12 #include <cppuhelper/bootstrap.hxx>
13 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
14 #include <com/sun/star/lang/XInitialization.hpp>
15 #include <com/sun/star/registry/XSimpleRegistry.hpp>
16 #include <com/sun/star/ucb/UniversalContentBroker.hpp>
18 #include <vcl/vclmain.hxx>
19 #include <vcl/layout.hxx>
20 #include <vcl/gdimtf.hxx>
21 #include <vcl/wmf.hxx>
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>
34 class DemoMtfWin
: public WorkWindow
39 explicit DemoMtfWin(const OUString
& rFileName
)
40 : WorkWindow(nullptr, WB_APP
| WB_STDWORK
)
42 SvFileStream
aFileStream(rFileName
, StreamMode::READ
);
44 if (aFileStream
.IsOpen())
46 ReadWindowMetafile(aFileStream
, maMtf
);
50 Application::Abort("Can't read metafile");
54 virtual void Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
) override
;
57 void DemoMtfWin::Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
)
59 maMtf
.Play(this, maMtf
.GetActionSize());
61 WorkWindow::Paint(rRenderContext
, rRect
);
64 class DemoMtfApp
: public Application
66 VclPtr
<DemoMtfWin
> mpWin
;
69 static void showHelp()
71 fprintf(stderr
, "Usage: mtfdemo --help | FILE\n");
72 fprintf(stderr
, "A VCL test app that displays Windows metafiles\n");
83 virtual int Main() override
87 mpWin
= VclPtr
<DemoMtfWin
>::Create(maFileName
);
88 mpWin
->SetText("Display metafile");
92 Application::Execute();
94 catch (const css::uno::Exception
& e
)
96 SAL_WARN("vcl.app", "Fatal: " << e
);
99 catch (const std::exception
& e
)
101 SAL_WARN("vcl.app", "Fatal: " << e
.what());
108 uno::Reference
<lang::XMultiServiceFactory
> xMSF
;
113 const sal_uInt16 nCmdParams
= GetCommandLineParamCount();
119 OUString aArg
= GetCommandLineParam(0);
121 if (aArg
== "--help" || aArg
== "-h")
127 uno::Reference
<uno::XComponentContext
> xComponentContext
128 = ::cppu::defaultBootstrap_InitialComponentContext();
129 xMSF
.set(xComponentContext
->getServiceManager(), uno::UNO_QUERY
);
131 Application::Abort("Bootstrap failure - no service manager");
133 ::comphelper::setProcessServiceFactory(xMSF
);
135 catch (const uno::Exception
&e
)
137 Application::Abort("Bootstrap exception " + e
.Message
);
141 void DeInit() override
143 uno::Reference
< lang::XComponent
>(
144 comphelper::getProcessComponentContext(),
145 uno::UNO_QUERY_THROW
)-> dispose();
146 ::comphelper::setProcessServiceFactory(nullptr);
152 void vclmain::createApplication()
154 static DemoMtfApp aApp
;
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */