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>
35 class DemoMtfWin
: public WorkWindow
40 explicit DemoMtfWin(const OUString
& rFileName
)
41 : WorkWindow(nullptr, WB_APP
| WB_STDWORK
)
43 SvFileStream
aFileStream(rFileName
, StreamMode::READ
);
45 if (aFileStream
.IsOpen())
47 ReadWindowMetafile(aFileStream
, maMtf
);
51 Application::Abort("Can't read metafile");
55 virtual void Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
) override
;
58 void DemoMtfWin::Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
)
60 maMtf
.Play(this, maMtf
.GetActionSize());
62 WorkWindow::Paint(rRenderContext
, rRect
);
65 class DemoMtfApp
: public Application
67 VclPtr
<DemoMtfWin
> mpWin
;
70 static void showHelp()
72 fprintf(stderr
, "Usage: mtfdemo --help | FILE\n");
73 fprintf(stderr
, "A VCL test app that displays Windows metafiles\n");
84 virtual int Main() override
88 mpWin
= VclPtr
<DemoMtfWin
>::Create(maFileName
);
89 mpWin
->SetText("Display metafile");
93 Application::Execute();
95 catch (const css::uno::Exception
&)
97 TOOLS_WARN_EXCEPTION("vcl.app", "Fatal");
100 catch (const std::exception
& e
)
102 SAL_WARN("vcl.app", "Fatal: " << e
.what());
109 uno::Reference
<lang::XMultiServiceFactory
> xMSF
;
114 const sal_uInt16 nCmdParams
= GetCommandLineParamCount();
120 OUString aArg
= GetCommandLineParam(0);
122 if (aArg
== "--help" || aArg
== "-h")
128 uno::Reference
<uno::XComponentContext
> xComponentContext
129 = ::cppu::defaultBootstrap_InitialComponentContext();
130 xMSF
.set(xComponentContext
->getServiceManager(), uno::UNO_QUERY
);
132 Application::Abort("Bootstrap failure - no service manager");
134 ::comphelper::setProcessServiceFactory(xMSF
);
136 catch (const uno::Exception
&e
)
138 Application::Abort("Bootstrap exception " + e
.Message
);
142 void DeInit() override
144 uno::Reference
< lang::XComponent
>(
145 comphelper::getProcessComponentContext(),
146 uno::UNO_QUERY_THROW
)-> dispose();
147 ::comphelper::setProcessServiceFactory(nullptr);
153 void vclmain::createApplication()
155 static DemoMtfApp aApp
;
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */