bump product version to 5.0.4.1
[LibreOffice.git] / vcl / workben / mtfdemo.cxx
blobe7da7a91724b2053dee92424b3dc617d2d8fd8ff
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 DemoMtfWin(OUString& aFileName)
44 : WorkWindow(NULL, WB_APP | WB_STDWORK)
46 SvFileStream aFileStream(aFileName, 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) 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;
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(NULL)
87 virtual int Main() SAL_OVERRIDE
89 try
91 mpWin = VclPtr<DemoMtfWin>::Create(maFileName);
92 mpWin->SetText(OUString("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() SAL_OVERRIDE
117 sal_uInt32 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 = uno::Reference<lang::XMultiServiceFactory>
134 (xComponentContext->getServiceManager(), uno::UNO_QUERY);
135 if(!xMSF.is())
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: */