Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / vcl / workben / mtfdemo.cxx
bloba9f52da4397a6c49be8f2b28c1616d5aeec20c46
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 <cstdlib>
32 using namespace css;
34 class DemoMtfWin : public WorkWindow
36 GDIMetaFile maMtf;
38 public:
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);
48 else
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;
67 OUString maFileName;
69 static void showHelp()
71 fprintf(stderr, "Usage: mtfdemo --help | FILE\n");
72 fprintf(stderr, "A VCL test app that displays Windows metafiles\n");
73 std::exit(0);
76 public:
78 DemoMtfApp()
79 : mpWin(nullptr)
83 virtual int Main() override
85 try
87 mpWin = VclPtr<DemoMtfWin>::Create(maFileName);
88 mpWin->SetText("Display metafile");
90 mpWin->Show();
92 Application::Execute();
94 catch (const css::uno::Exception& e)
96 SAL_WARN("vcl.app", "Fatal: " << e);
97 return 1;
99 catch (const std::exception& e)
101 SAL_WARN("vcl.app", "Fatal: " << e.what());
102 return 1;
104 return 0;
107 private:
108 uno::Reference<lang::XMultiServiceFactory> xMSF;
109 void Init() override
113 const sal_uInt16 nCmdParams = GetCommandLineParamCount();
115 if (nCmdParams == 0)
116 showHelp();
117 else
119 OUString aArg = GetCommandLineParam(0);
121 if (aArg == "--help" || aArg == "-h")
122 showHelp();
123 else
124 maFileName = aArg;
127 uno::Reference<uno::XComponentContext> xComponentContext
128 = ::cppu::defaultBootstrap_InitialComponentContext();
129 xMSF.set(xComponentContext->getServiceManager(), uno::UNO_QUERY);
130 if(!xMSF.is())
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: */