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>
30 #include <tools/stream.hxx>
34 using namespace com::sun::star
;
38 class DemoMtfWin
: public WorkWindow
43 DemoMtfWin(OUString
& aFileName
)
44 : WorkWindow(NULL
, WB_APP
| WB_STDWORK
)
46 SvFileStream
aFileStream(aFileName
, StreamMode::READ
);
48 if (aFileStream
.IsOpen())
50 ReadWindowMetafile(aFileStream
, maMtf
);
54 Application::Abort("Can't read metafile");
58 virtual void Paint(vcl::RenderContext
& rRenderContext
, const Rectangle
& rRect
) SAL_OVERRIDE
;
61 void DemoMtfWin::Paint(vcl::RenderContext
& rRenderContext
, const Rectangle
& rRect
)
63 maMtf
.Play(this, maMtf
.GetActionSize());
65 WorkWindow::Paint(rRenderContext
, rRect
);
68 class DemoMtfApp
: public Application
70 VclPtr
<DemoMtfWin
> mpWin
;
73 static void showHelp()
75 fprintf(stderr
, "Usage: mtfdemo --help | FILE\n");
76 fprintf(stderr
, "A VCL test app that displays Windows metafiles\n");
87 virtual int Main() SAL_OVERRIDE
91 mpWin
= VclPtr
<DemoMtfWin
>::Create(maFileName
);
92 mpWin
->SetText(OUString("Display metafile"));
96 Application::Execute();
98 catch (const css::uno::Exception
& e
)
100 SAL_WARN("vcl.app", "Fatal exception: " << e
.Message
);
103 catch (const std::exception
& e
)
105 SAL_WARN("vcl.app", "Fatal exception: " << e
.what());
112 uno::Reference
<lang::XMultiServiceFactory
> xMSF
;
113 void Init() SAL_OVERRIDE
117 sal_uInt32 nCmdParams
= GetCommandLineParamCount();
123 OUString aArg
= GetCommandLineParam(0);
125 if (aArg
== "--help" || aArg
== "-h")
131 uno::Reference
<uno::XComponentContext
> xComponentContext
132 = ::cppu::defaultBootstrap_InitialComponentContext();
133 xMSF
= uno::Reference
<lang::XMultiServiceFactory
>
134 (xComponentContext
->getServiceManager(), uno::UNO_QUERY
);
136 Application::Abort("Bootstrap failure - no service manager");
138 ::comphelper::setProcessServiceFactory(xMSF
);
140 catch (const uno::Exception
&e
)
142 Application::Abort("Bootstrap exception " + e
.Message
);
146 void DeInit() SAL_OVERRIDE
148 uno::Reference
< lang::XComponent
>(
149 comphelper::getProcessComponentContext(),
150 uno::UNO_QUERY_THROW
)-> dispose();
151 ::comphelper::setProcessServiceFactory(NULL
);
157 void vclmain::createApplication()
159 static DemoMtfApp aApp
;
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */