LCOV - code coverage report
Current view: top level - sw/qa/tiledrendering - tiledrendering.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 72 0.0 %
Date: 2014-11-03 Functions: 0 16 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 <cppuhelper/bootstrap.hxx>
      12             : #include <osl/file.hxx>
      13             : #include <vcl/builder.hxx>
      14             : #include <vcl/dialog.hxx>
      15             : #include <vcl/help.hxx>
      16             : #include <vcl/svapp.hxx>
      17             : #include <vcl/vclmain.hxx>
      18             : #include <vcl/field.hxx>
      19             : #include <vcl/button.hxx>
      20             : #include <vcl/fixed.hxx>
      21             : #include <vcl/virdev.hxx>
      22             : #include <sfx2/filedlghelper.hxx>
      23             : #include <swmodule.hxx>
      24             : #include <wrtsh.hxx>
      25             : 
      26             : #include <com/sun/star/lang/XComponent.hpp>
      27             : #include <com/sun/star/lang/XMultiComponentFactory.hpp>
      28             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      29             : #include <com/sun/star/ucb/UniversalContentBroker.hpp>
      30             : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
      31             : #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
      32             : #include <com/sun/star/uno/XInterface.hpp>
      33             : #include <com/sun/star/frame/XComponentLoader.hpp>
      34             : #include <com/sun/star/frame/Desktop.hpp>
      35             : #include <com/sun/star/beans/XPropertySet.hpp>
      36             : 
      37             : using namespace ::com::sun::star;
      38             : using namespace ::com::sun::star::uno;
      39             : using namespace ::com::sun::star::ui::dialogs;
      40             : using namespace ::sfx2;
      41             : 
      42           0 : class TiledRenderingApp : public Application
      43             : {
      44             : private:
      45             :     uno::Reference<uno::XComponentContext> xContext;
      46             :     uno::Reference<lang::XMultiComponentFactory> xFactory;
      47             :     uno::Reference<lang::XMultiServiceFactory> xSFactory;
      48             :     uno::Reference<uno::XInterface> xDesktop;
      49             :     uno::Reference<frame::XComponentLoader> xLoader;
      50             :     uno::Reference<lang::XComponent> xComponent;
      51             : public:
      52             :     virtual void Init() SAL_OVERRIDE;
      53             :     virtual int Main() SAL_OVERRIDE;
      54             :     void Open(OUString & aFileUrl);
      55             : };
      56             : 
      57             : class TiledRenderingDialog: public ModalDialog
      58             : {
      59             : private:
      60             :     TiledRenderingApp *mpApp;
      61             :     NumericField *mpContextWidth;
      62             :     NumericField *mpContextHeight;
      63             :     NumericField *mpTilePosX;
      64             :     NumericField *mpTilePosY;
      65             :     NumericField *mpTileWidth;
      66             :     NumericField *mpTileHeight;
      67             :     FixedImage *mpImage;
      68             : 
      69             : public:
      70           0 :     TiledRenderingDialog(TiledRenderingApp * app) :
      71             :         ModalDialog(DIALOG_NO_PARENT, "TiledRendering", "qa/sw/ui/tiledrendering.ui"),
      72           0 :         mpApp(app)
      73             :     {
      74             :         PushButton * renderButton;
      75           0 :         get(renderButton, "buttonRenderTile");
      76           0 :         renderButton->SetClickHdl( LINK( this, TiledRenderingDialog, RenderHdl));
      77             : 
      78             :         PushButton * chooseDocumentButton;
      79           0 :         get(chooseDocumentButton, "buttonChooseDocument");
      80           0 :         chooseDocumentButton->SetClickHdl( LINK( this, TiledRenderingDialog, ChooseDocumentHdl));
      81             : 
      82           0 :         SetStyle(GetStyle()|WB_CLOSEABLE);
      83             : 
      84           0 :         get(mpContextWidth, "spinContextWidth");
      85           0 :         get(mpContextHeight, "spinContextHeight");
      86           0 :         get(mpTilePosX, "spinTilePosX");
      87           0 :         get(mpTilePosY, "spinTilePosY");
      88           0 :         get(mpTileWidth, "spinTileWidth");
      89           0 :         get(mpTileHeight, "spinTileHeight");
      90           0 :         get(mpImage, "imageTile");
      91           0 :     }
      92             : 
      93           0 :     virtual ~TiledRenderingDialog()
      94           0 :     {
      95           0 :     }
      96             : 
      97             :     DECL_LINK ( RenderHdl, Button * );
      98             :     DECL_LINK ( ChooseDocumentHdl, Button * );
      99             : };
     100             : 
     101           0 : IMPL_LINK ( TiledRenderingDialog, RenderHdl, Button *, EMPTYARG )
     102             : {
     103           0 :     int contextWidth = mpContextWidth->GetValue();
     104           0 :     int contextHeight = mpContextHeight->GetValue();
     105           0 :     int tilePosX = mpTilePosX->GetValue();
     106           0 :     int tilePosY = mpTilePosY->GetValue();
     107           0 :     long tileWidth = mpTileWidth->GetValue();
     108           0 :     long tileHeight = mpTileHeight->GetValue();
     109             : 
     110             :     // do the same thing we are doing in touch_lo_draw_tile()
     111           0 :     SwWrtShell *pViewShell = GetActiveWrtShell();
     112             : 
     113           0 :     if (pViewShell)
     114             :     {
     115             :         // TODO create a VirtualDevice based on SystemGraphicsData instead so
     116             :         // that we get direct rendering; something like:
     117             :         //
     118             :         // SystemGraphicsData aData;
     119             :         // [setup the aData]
     120             :         // VirtualDevice aDevice(&aData, [color depth]);
     121           0 :         VirtualDevice aDevice;
     122             : 
     123             :         // paint to it
     124           0 :         pViewShell->PaintTile(aDevice, contextWidth, contextHeight, tilePosX, tilePosY, tileWidth, tileHeight);
     125             : 
     126             :         // copy the aDevice content to mpImage
     127           0 :         Bitmap aBitmap(aDevice.GetBitmap(aDevice.PixelToLogic(Point(0,0)), aDevice.PixelToLogic(Size(contextWidth, contextHeight))));
     128           0 :         mpImage->SetImage(Image(aBitmap));
     129             : 
     130             :         // update the dialog size
     131           0 :         setOptimalLayoutSize();
     132             :     }
     133             : 
     134           0 :     return 1;
     135             : }
     136             : 
     137           0 : IMPL_LINK ( TiledRenderingDialog,  ChooseDocumentHdl, Button *, EMPTYARG )
     138             : {
     139           0 :     FileDialogHelper aDlgHelper( TemplateDescription::FILEOPEN_SIMPLE, 0 );
     140           0 :     uno::Reference < XFilePicker > xFP = aDlgHelper.GetFilePicker();
     141           0 :     if( aDlgHelper.Execute() == ERRCODE_NONE )
     142             :     {
     143           0 :         OUString aFileUrl =xFP->getFiles().getConstArray()[0];
     144           0 :         mpApp->Open(aFileUrl);
     145             :     }
     146           0 :     return 1;
     147             : }
     148             : 
     149           0 : void TiledRenderingApp::Open(OUString & aFileUrl)
     150             : {
     151           0 :     static const OUString TARGET("_default");
     152           0 :     static const Sequence<beans::PropertyValue> PROPS (0);
     153           0 :     if(xComponent.get())
     154             :     {
     155           0 :         xComponent->dispose();
     156           0 :         xComponent.clear();
     157             :     }
     158           0 :     xComponent.set(xLoader->loadComponentFromURL(aFileUrl, TARGET, 0, PROPS));
     159           0 : }
     160             : 
     161           0 : void TiledRenderingApp::Init()
     162             : {
     163           0 :     xContext.set(cppu::defaultBootstrap_InitialComponentContext());
     164           0 :     xFactory.set(xContext->getServiceManager());
     165           0 :     xSFactory.set(uno::Reference<lang::XMultiServiceFactory> (xFactory, uno::UNO_QUERY_THROW));
     166           0 :     comphelper::setProcessServiceFactory(xSFactory);
     167             : 
     168             :     // Create UCB (for backwards compatibility, in case some code still uses
     169             :     // plain createInstance w/o args directly to obtain an instance):
     170           0 :     ::ucb::UniversalContentBroker::create(comphelper::getProcessComponentContext() );
     171             : 
     172           0 :     xDesktop.set(xFactory->createInstanceWithContext(OUString("com.sun.star.frame.Desktop"), xContext));
     173           0 :     xLoader.set(frame::Desktop::create(xContext));
     174           0 : }
     175             : 
     176           0 : int TiledRenderingApp::Main()
     177             : {
     178           0 :     if(GetCommandLineParamCount()>0)
     179             :     {
     180           0 :         OUString aFileUrl;
     181           0 :         osl::File::getFileURLFromSystemPath(GetCommandLineParam(0), aFileUrl);
     182           0 :         Open(aFileUrl);
     183             :     }
     184           0 :     Help::EnableQuickHelp();
     185             :     try
     186             :     {
     187           0 :         TiledRenderingDialog pDialog(this);
     188           0 :         pDialog.Execute();
     189             :     }
     190           0 :     catch (const uno::Exception &e)
     191             :     {
     192           0 :         fprintf(stderr, "fatal error: %s\n", OUStringToOString(e.Message, osl_getThreadTextEncoding()).getStr());
     193             :     }
     194           0 :     return EXIT_SUCCESS;
     195             : }
     196             : 
     197           0 : void vclmain::createApplication()
     198             : {
     199           0 :     static TiledRenderingApp aApp;
     200           0 : }
     201             : 
     202             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10