build fix
[LibreOffice.git] / vcl / workben / mtfdemo.cxx
blob3c842f9da649b46370691fb7f2f9caad96207505
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
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>
32 #include <cstdlib>
34 using namespace com::sun::star;
36 using namespace css;
38 class DemoMtfWin : public WorkWindow
40 GDIMetaFile maMtf;
42 public:
43 explicit DemoMtfWin(const OUString& rFileName)
44 : WorkWindow(nullptr, WB_APP | WB_STDWORK)
46 SvFileStream aFileStream(rFileName, StreamMode::READ);
48 if (aFileStream.IsOpen())
50 ReadWindowMetafile(aFileStream, maMtf);
52 else
54 Application::Abort("Can't read metafile");
58 virtual void Paint(vcl::RenderContext& rRenderContext, const Rectangle& rRect) 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;
71 OUString maFileName;
73 static void showHelp()
75 fprintf(stderr, "Usage: mtfdemo --help | FILE\n");
76 fprintf(stderr, "A VCL test app that displays Windows metafiles\n");
77 std::exit(0);
80 public:
82 DemoMtfApp()
83 : mpWin(nullptr)
87 virtual int Main() override
89 try
91 mpWin = VclPtr<DemoMtfWin>::Create(maFileName);
92 mpWin->SetText("Display metafile");
94 mpWin->Show();
96 Application::Execute();
98 catch (const css::uno::Exception& e)
100 SAL_WARN("vcl.app", "Fatal exception: " << e.Message);
101 return 1;
103 catch (const std::exception& e)
105 SAL_WARN("vcl.app", "Fatal exception: " << e.what());
106 return 1;
108 return 0;
111 protected:
112 uno::Reference<lang::XMultiServiceFactory> xMSF;
113 void Init() override
117 const sal_uInt16 nCmdParams = GetCommandLineParamCount();
119 if (nCmdParams == 0)
120 showHelp();
121 else
123 OUString aArg = GetCommandLineParam(0);
125 if (aArg == "--help" || aArg == "-h")
126 showHelp();
127 else
128 maFileName = aArg;
131 uno::Reference<uno::XComponentContext> xComponentContext
132 = ::cppu::defaultBootstrap_InitialComponentContext();
133 xMSF.set(xComponentContext->getServiceManager(), uno::UNO_QUERY);
134 if(!xMSF.is())
135 Application::Abort("Bootstrap failure - no service manager");
137 ::comphelper::setProcessServiceFactory(xMSF);
139 catch (const uno::Exception &e)
141 Application::Abort("Bootstrap exception " + e.Message);
145 void DeInit() override
147 uno::Reference< lang::XComponent >(
148 comphelper::getProcessComponentContext(),
149 uno::UNO_QUERY_THROW)-> dispose();
150 ::comphelper::setProcessServiceFactory(nullptr);
156 void vclmain::createApplication()
158 static DemoMtfApp aApp;
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */