LCOV - code coverage report
Current view: top level - vcl/workben - mtfdemo.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 55 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 14 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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             :  */
       9             : 
      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>
      17             : 
      18             : #include <vcl/vclmain.hxx>
      19             : #include <vcl/layout.hxx>
      20             : #include <vcl/gdimtf.hxx>
      21             : #include <vcl/wmf.hxx>
      22             : 
      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             : 
      30             : #include <tools/stream.hxx>
      31             : 
      32             : #include <cstdlib>
      33             : 
      34             : using namespace com::sun::star;
      35             : 
      36             : using namespace css;
      37             : 
      38           0 : class DemoMtfWin : public WorkWindow
      39             : {
      40             :     GDIMetaFile maMtf;
      41             : 
      42             : public:
      43           0 :     explicit DemoMtfWin(const OUString& rFileName)
      44           0 :         : WorkWindow(NULL, WB_APP | WB_STDWORK)
      45             :     {
      46           0 :         SvFileStream aFileStream(rFileName, StreamMode::READ);
      47             : 
      48           0 :         if (aFileStream.IsOpen())
      49             :         {
      50           0 :             ReadWindowMetafile(aFileStream, maMtf);
      51             :         }
      52             :         else
      53             :         {
      54           0 :             Application::Abort("Can't read metafile");
      55           0 :         }
      56           0 :     }
      57             : 
      58             :     virtual void Paint(vcl::RenderContext& rRenderContext, const Rectangle& rRect)  SAL_OVERRIDE;
      59             : };
      60             : 
      61           0 : void DemoMtfWin::Paint(vcl::RenderContext& rRenderContext, const Rectangle& rRect)
      62             : {
      63           0 :     maMtf.Play(this, maMtf.GetActionSize());
      64             : 
      65           0 :     WorkWindow::Paint(rRenderContext, rRect);
      66           0 : }
      67             : 
      68           0 : class DemoMtfApp : public Application
      69             : {
      70             :     VclPtr<DemoMtfWin> mpWin;
      71             :     OUString maFileName;
      72             : 
      73           0 :     static void showHelp()
      74             :     {
      75           0 :         fprintf(stderr, "Usage: mtfdemo --help | FILE\n");
      76           0 :         fprintf(stderr, "A VCL test app that displays Windows metafiles\n");
      77           0 :         std::exit(0);
      78             :     }
      79             : 
      80             : public:
      81             : 
      82           0 :     DemoMtfApp()
      83           0 :         : mpWin(NULL)
      84             :     {
      85           0 :     }
      86             : 
      87           0 :     virtual int Main() SAL_OVERRIDE
      88             :     {
      89             :         try
      90             :         {
      91           0 :             mpWin = VclPtr<DemoMtfWin>::Create(maFileName);
      92           0 :             mpWin->SetText(OUString("Display metafile"));
      93             : 
      94           0 :             mpWin->Show();
      95             : 
      96           0 :             Application::Execute();
      97             :         }
      98           0 :         catch (const css::uno::Exception& e)
      99             :         {
     100             :             SAL_WARN("vcl.app", "Fatal exception: " << e.Message);
     101           0 :             return 1;
     102             :         }
     103           0 :         catch (const std::exception& e)
     104             :         {
     105             :             SAL_WARN("vcl.app", "Fatal exception: " << e.what());
     106           0 :             return 1;
     107             :         }
     108           0 :         return 0;
     109             :     }
     110             : 
     111             : protected:
     112             :     uno::Reference<lang::XMultiServiceFactory> xMSF;
     113           0 :     void Init() SAL_OVERRIDE
     114             :     {
     115             :         try
     116             :         {
     117           0 :             sal_uInt32 nCmdParams = GetCommandLineParamCount();
     118             : 
     119           0 :             if (nCmdParams == 0)
     120           0 :                 showHelp();
     121             :             else
     122             :             {
     123           0 :                 OUString aArg = GetCommandLineParam(0);
     124             : 
     125           0 :                 if (aArg == "--help" || aArg == "-h")
     126           0 :                     showHelp();
     127             :                 else
     128           0 :                     maFileName = aArg;
     129             :             }
     130             : 
     131             :             uno::Reference<uno::XComponentContext> xComponentContext
     132           0 :                 = ::cppu::defaultBootstrap_InitialComponentContext();
     133           0 :             xMSF = uno::Reference<lang::XMultiServiceFactory>
     134           0 :                 (xComponentContext->getServiceManager(), uno::UNO_QUERY);
     135           0 :             if(!xMSF.is())
     136           0 :                 Application::Abort("Bootstrap failure - no service manager");
     137             : 
     138           0 :             ::comphelper::setProcessServiceFactory(xMSF);
     139             :         }
     140           0 :         catch (const uno::Exception &e)
     141             :         {
     142           0 :             Application::Abort("Bootstrap exception " + e.Message);
     143             :         }
     144           0 :     }
     145             : 
     146           0 :     void DeInit() SAL_OVERRIDE
     147             :     {
     148             :         uno::Reference< lang::XComponent >(
     149             :             comphelper::getProcessComponentContext(),
     150           0 :         uno::UNO_QUERY_THROW)-> dispose();
     151           0 :         ::comphelper::setProcessServiceFactory(NULL);
     152           0 :     }
     153             : 
     154             : };
     155             : 
     156             : 
     157           0 : void vclmain::createApplication()
     158             : {
     159           0 :     static DemoMtfApp aApp;
     160           0 : }
     161             : 
     162             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11