bump product version to 7.2.5.1
[LibreOffice.git] / vcl / workben / mtfdemo.cxx
blobafdb0192f16f85282265db709ba754e130543745
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 <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>
31 #include <cstdlib>
33 using namespace css;
35 namespace {
37 class DemoMtfWin : public WorkWindow
39 GDIMetaFile maMtf;
41 public:
42 explicit DemoMtfWin(const OUString& rFileName)
43 : WorkWindow(nullptr, WB_APP | WB_STDWORK)
45 SvFileStream aFileStream(rFileName, StreamMode::READ);
47 if (aFileStream.IsOpen())
49 ReadWindowMetafile(aFileStream, maMtf);
51 else
53 Application::Abort("Can't read metafile");
57 virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override;
62 void DemoMtfWin::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect)
64 maMtf.Play(*GetOutDev(), maMtf.GetActionSize());
66 WorkWindow::Paint(rRenderContext, rRect);
69 namespace {
71 class DemoMtfApp : public Application
73 VclPtr<DemoMtfWin> mpWin;
74 OUString maFileName;
76 static void showHelp()
78 fprintf(stderr, "Usage: mtfdemo --help | FILE\n");
79 fprintf(stderr, "A VCL test app that displays Windows metafiles\n");
80 std::exit(0);
83 public:
85 DemoMtfApp()
86 : mpWin(nullptr)
90 virtual int Main() override
92 try
94 mpWin = VclPtr<DemoMtfWin>::Create(maFileName);
95 mpWin->SetText("Display metafile");
97 mpWin->Show();
99 Application::Execute();
101 catch (const css::uno::Exception&)
103 TOOLS_WARN_EXCEPTION("vcl.app", "Fatal");
104 return 1;
106 catch (const std::exception& e)
108 SAL_WARN("vcl.app", "Fatal: " << e.what());
109 return 1;
111 return 0;
114 private:
115 uno::Reference<lang::XMultiServiceFactory> xMSF;
116 void Init() override
120 const sal_uInt16 nCmdParams = GetCommandLineParamCount();
122 if (nCmdParams == 0)
123 showHelp();
124 else
126 OUString aArg = GetCommandLineParam(0);
128 if (aArg == "--help" || aArg == "-h")
129 showHelp();
130 else
131 maFileName = aArg;
134 uno::Reference<uno::XComponentContext> xComponentContext
135 = ::cppu::defaultBootstrap_InitialComponentContext();
136 xMSF.set(xComponentContext->getServiceManager(), uno::UNO_QUERY);
137 if(!xMSF.is())
138 Application::Abort("Bootstrap failure - no service manager");
140 ::comphelper::setProcessServiceFactory(xMSF);
142 catch (const uno::Exception &e)
144 Application::Abort("Bootstrap exception " + e.Message);
148 void DeInit() override
150 uno::Reference< lang::XComponent >(
151 comphelper::getProcessComponentContext(),
152 uno::UNO_QUERY_THROW)-> dispose();
153 ::comphelper::setProcessServiceFactory(nullptr);
160 void vclmain::createApplication()
162 static DemoMtfApp aApp;
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */