diff options
author | Jan-Marek Glogowski <glogow@fbihome.de> | 2018-12-18 18:32:13 +0000 |
---|---|---|
committer | Jan-Marek Glogowski <glogow@fbihome.de> | 2018-12-20 14:13:23 +0100 |
commit | a4749a48677b26c8b9ba9cf36f5c9bf62ed9ed8a (patch) | |
tree | 7a438f43129058c6dd77c33e13d95366e964ffdd /canvas/workben | |
parent | 718c9b8a42987dd19252d539c38909305839c946 (diff) |
Convert canvasdemo to gbuild
Change-Id: Ieb3b1846a5a31915297cdc80053dba3d1656aba2
Reviewed-on: https://gerrit.libreoffice.org/65365
Tested-by: Jenkins
Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
Diffstat (limited to 'canvas/workben')
-rw-r--r-- | canvas/workben/canvasdemo.cxx | 150 | ||||
-rw-r--r-- | canvas/workben/makefile.mk | 55 |
2 files changed, 76 insertions, 129 deletions
diff --git a/canvas/workben/canvasdemo.cxx b/canvas/workben/canvasdemo.cxx index 20b345e5060a..c4b261c2a28d 100644 --- a/canvas/workben/canvasdemo.cxx +++ b/canvas/workben/canvasdemo.cxx @@ -17,20 +17,14 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ - // This code strongly inspired by Miguel / Federico's Gnome Canvas demo code. #include <sal/config.h> -#include <stdio.h> -#include <unistd.h> - #include <basegfx/polygon/b2dpolygon.hxx> #include <basegfx/polygon/b2dpolygontools.hxx> #include <basegfx/utils/canvastools.hxx> -#include <com/sun/star/lang/XInitialization.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp> -#include <com/sun/star/registry/XSimpleRegistry.hpp> #include <com/sun/star/rendering/CompositeOperation.hpp> #include <com/sun/star/rendering/FillRule.hpp> #include <com/sun/star/rendering/PathCapType.hpp> @@ -44,49 +38,37 @@ #include <com/sun/star/ucb/UniversalContentBroker.hpp> #include <comphelper/processfactory.hxx> #include <cppuhelper/bootstrap.hxx> -#include <cppuhelper/servicefactory.hxx> -#include <rtl/bootstrap.hxx> -#include <sal/macros.h> #include <vcl/canvastools.hxx> #include <vcl/svapp.hxx> +#include <vcl/vclmain.hxx> #include <vcl/virdev.hxx> #include <vcl/window.hxx> +#include <vcl/wrkwin.hxx> - -// never import whole leaf namespaces, since this will result in -// absolutely weird effects during (Koenig) name lookup using namespace ::com::sun::star; - -class DemoApp : public Application -{ -public: - virtual void Main(); - virtual void Exception( ExceptionCategory nCategory ); -}; - static void PrintHelp() { fprintf( stdout, "canvasdemo - Exercise the new canvas impl\n" ); } -class TestWindow : public Dialog +class TestWindow : public WorkWindow { public: - TestWindow() : Dialog( (vcl::Window *) NULL ) + TestWindow() : WorkWindow(nullptr, WB_APP | WB_STDWORK) { - SetText( OUString( "Canvas test" ) ); + SetText("Canvas test"); SetSizePixel( Size( 600, 450 ) ); EnablePaint( true ); Show(); } - virtual ~TestWindow() {} - virtual void MouseButtonUp( const MouseEvent& /*rMEvt*/ ) + virtual ~TestWindow() override {} + virtual void MouseButtonUp( const MouseEvent& /*rMEvt*/ ) override { //TODO: do something cool - EndDialog(); + Application::Quit(); } - virtual void Paint( const Rectangle& rRect ); + virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override; }; class DemoRenderer @@ -130,8 +112,8 @@ class DemoRenderer //but nothing changes maRenderState.CompositeOperation = rendering::CompositeOperation::OVER; - maBox.Width() = aSize.Width() / 3; - maBox.Height() = aSize.Height() / 3; + maBox.setWidth(aSize.Width() / 3); + maBox.setHeight(aSize.Height() / 3); lang::Locale aLocale; rendering::FontInfo aFontInfo; @@ -173,7 +155,7 @@ class DemoRenderer mxCanvas->drawText( aText, mxDefaultFont, maViewState, aRenderState, 0); } - void drawRect( Rectangle rRect, uno::Sequence< double > &aColor, int /*nWidth*/ ) + void drawRect( tools::Rectangle rRect, uno::Sequence< double > &aColor, int /*nWidth*/ ) { uno::Sequence< geometry::RealPoint2D > aPoints(4); uno::Reference< rendering::XLinePolyPolygon2D > xPoly; @@ -298,11 +280,11 @@ class DemoRenderer drawTitle( OString( "Rectangles" ) ); - drawRect( Rectangle( 20, 30, 70, 60 ), maColorRed, 8 ); + drawRect( tools::Rectangle( 20, 30, 70, 60 ), maColorRed, 8 ); // color mediumseagreen, stipple fill, outline black - drawRect( Rectangle( 90, 40, 180, 100 ), maColorBlack, 4 ); + drawRect( tools::Rectangle( 90, 40, 180, 100 ), maColorBlack, 4 ); // color steelblue, filled, no outline - drawRect( Rectangle( 10, 80, 80, 140 ), maColorBlack, 1 ); + drawRect( tools::Rectangle( 10, 80, 80, 140 ), maColorBlack, 1 ); maRenderState = maOldRenderState; // pop } @@ -444,7 +426,7 @@ class DemoRenderer double gimmerand() { - return (double)(rand()) / RAND_MAX * 100 + 50; + return static_cast<double>(rand()) / RAND_MAX * 100 + 50; } void drawArcs() @@ -555,18 +537,15 @@ class DemoRenderer }; -void TestWindow::Paint( const Rectangle& /*rRect*/ ) +void TestWindow::Paint(vcl::RenderContext&, const tools::Rectangle&) { try { - const Size aVDevSize(300,300); - VirtualDevice aVDev(*this); - aVDev.SetOutputSizePixel(aVDevSize); - uno::Reference< rendering::XCanvas > xVDevCanvas( aVDev.GetCanvas(), + uno::Reference< rendering::XCanvas > xVDevCanvas( GetCanvas(), uno::UNO_QUERY_THROW ); uno::Reference< rendering::XGraphicDevice > xVDevDevice( xVDevCanvas->getDevice(), uno::UNO_QUERY_THROW ); - DemoRenderer aVDevRenderer( xVDevDevice, xVDevCanvas, aVDevSize); + DemoRenderer aVDevRenderer( xVDevDevice, xVDevCanvas, GetSizePixel()); xVDevCanvas->clear(); aVDevRenderer.drawGrid(); aVDevRenderer.drawRectangles(); @@ -607,7 +586,7 @@ void TestWindow::Paint( const Rectangle& /*rRect*/ ) uno::Reference< rendering::XSpriteCanvas > xSpriteCanvas( xCanvas, uno::UNO_QUERY ); if( xSpriteCanvas.is() ) - xSpriteCanvas->updateScreen( sal_True ); // without + xSpriteCanvas->updateScreen( true ); // without // updateScreen(), // nothing is // visible @@ -619,21 +598,22 @@ void TestWindow::Paint( const Rectangle& /*rRect*/ ) } } -void DemoApp::Exception( ExceptionCategory nCategory ) +class DemoApp : public Application { - switch( nCategory ) - { - case ExceptionCategory::ResourceNotLoaded: - Abort( "Error: could not load language resources.\nPlease check your installation.\n" ); - break; - } -} +public: + virtual int Main() override; + virtual void Exception(ExceptionCategory nCategory) override; -void DemoApp::Main() +protected: + void Init() override; + void DeInit() override; +}; + +int DemoApp::Main() { bool bHelp = false; - for( USHORT i = 0; i < GetCommandLineParamCount(); i++ ) + for( unsigned int i = 0; i < GetCommandLineParamCount(); i++ ) { OUString aParam = GetCommandLineParam( i ); @@ -644,42 +624,64 @@ void DemoApp::Main() if( bHelp ) { PrintHelp(); - return; + return 1; } + // Create UCB (for backwards compatibility, in case some code still uses + // plain createInstance w/o args directly to obtain an instance): + ::ucb::UniversalContentBroker::create( + comphelper::getProcessComponentContext() ); + + ScopedVclPtr<TestWindow> aWindow = VclPtr<TestWindow>::Create(); + aWindow->Show(); - // create the global service-manager + Application::Execute(); + return 0; +} - uno::Reference< lang::XMultiServiceFactory > xFactory; - try +void DemoApp::Exception( ExceptionCategory nCategory ) +{ + switch( nCategory ) { - uno::Reference< uno::XComponentContext > xCtx = ::cppu::defaultBootstrap_InitialComponentContext(); - xFactory.set( xCtx->getServiceManager(), uno::UNO_QUERY ); - if( xFactory.is() ) - ::comphelper::setProcessServiceFactory( xFactory ); + case ExceptionCategory::ResourceNotLoaded: + Abort( "Error: could not load language resources.\nPlease check your installation.\n" ); + break; + default: + break; } - catch( const uno::Exception& ) +} + +void DemoApp::Init() +{ + try { + uno::Reference<uno::XComponentContext> xComponentContext + = ::cppu::defaultBootstrap_InitialComponentContext(); + uno::Reference<lang::XMultiServiceFactory> xMSF; + xMSF.set(xComponentContext->getServiceManager(), uno::UNO_QUERY); + if(!xMSF.is()) + Application::Abort("Bootstrap failure - no service manager"); + + ::comphelper::setProcessServiceFactory(xMSF); } - - if( !xFactory.is() ) + catch (const uno::Exception &e) { - fprintf( stderr, "Could not bootstrap UNO, installation must be in disorder. Exiting.\n" ); - exit( 1 ); + Application::Abort("Bootstrap exception " + e.Message); } +} - // Create UCB (for backwards compatibility, in case some code still uses - // plain createInstance w/o args directly to obtain an instance): - ::ucb::UniversalContentBroker::create( - comphelper::getProcessComponentContext() ); - - InitVCL(); - TestWindow pWindow; - pWindow.Execute(); - DeInitVCL(); +void DemoApp::DeInit() +{ + uno::Reference< lang::XComponent >( + comphelper::getProcessComponentContext(), + uno::UNO_QUERY_THROW)-> dispose(); + ::comphelper::setProcessServiceFactory(nullptr); } -DemoApp aDemoApp; +void vclmain::createApplication() +{ + static DemoApp aApp; +} // TODO // - bouncing clip-rectangle mode - bounce a clip-rect around the window... diff --git a/canvas/workben/makefile.mk b/canvas/workben/makefile.mk deleted file mode 100644 index e3e017dcf42f..000000000000 --- a/canvas/workben/makefile.mk +++ /dev/null @@ -1,55 +0,0 @@ -# -# This file is part of the LibreOffice project. -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. -# -# This file incorporates work covered by the following license notice: -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed -# with this work for additional information regarding copyright -# ownership. The ASF licenses this file to you under the Apache -# License, Version 2.0 (the "License"); you may not use this file -# except in compliance with the License. You may obtain a copy of -# the License at http://www.apache.org/licenses/LICENSE-2.0 . -# - -PRJ=.. - -PRJNAME=canvas -TARGET=canvasdemo -TARGETTYPE=GUI -LIBTARGET=NO - -ENABLE_EXCEPTIONS=TRUE - - -# --- Settings ----------------------------------------------------- - -.INCLUDE : settings.mk - -# --- Files -------------------------------------------------------- - -APP1TARGET= $(TARGET) - -APP1OBJS= \ - $(OBJ)$/canvasdemo.obj - -APP1STDLIBS=$(TOOLSLIB) \ - $(COMPHELPERLIB) \ - $(CPPULIB) \ - $(CPPUHELPERLIB) \ - $(UCBHELPERLIB) \ - $(SALLIB) \ - $(VCLLIB) \ - $(BASEGFXLIB) - -.IF "$(OS)"=="WNT" -APP1DEF= $(MISC)$/$(TARGET).def -.ENDIF - -# --- Targets ------------------------------------------------------ - -.INCLUDE : target.mk |