2010-10-14 08:27:31 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-10-08 10:00:18 +01:00
|
|
|
/*
|
|
|
|
* 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 .
|
|
|
|
*/
|
2006-09-17 02:32:22 +00:00
|
|
|
|
2006-03-15 16:17:57 +00:00
|
|
|
// This code strongly inspired by Miguel / Federico's Gnome Canvas demo code.
|
|
|
|
|
2015-08-10 14:04:31 -05:00
|
|
|
#include <sal/config.h>
|
|
|
|
|
2006-04-04 14:37:19 +00:00
|
|
|
#include <basegfx/polygon/b2dpolygon.hxx>
|
|
|
|
#include <basegfx/polygon/b2dpolygontools.hxx>
|
2017-09-22 14:12:07 +03:00
|
|
|
#include <basegfx/utils/canvastools.hxx>
|
2015-08-10 14:04:31 -05:00
|
|
|
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
|
|
|
|
#include <com/sun/star/rendering/CompositeOperation.hpp>
|
2006-03-15 16:17:57 +00:00
|
|
|
#include <com/sun/star/rendering/PathCapType.hpp>
|
|
|
|
#include <com/sun/star/rendering/PathJoinType.hpp>
|
2015-08-10 14:04:31 -05:00
|
|
|
#include <com/sun/star/rendering/RenderState.hpp>
|
|
|
|
#include <com/sun/star/rendering/ViewState.hpp>
|
2006-03-15 16:17:57 +00:00
|
|
|
#include <com/sun/star/rendering/XBitmap.hpp>
|
2015-08-10 14:04:31 -05:00
|
|
|
#include <com/sun/star/rendering/XCanvas.hpp>
|
|
|
|
#include <com/sun/star/rendering/XGraphicDevice.hpp>
|
|
|
|
#include <com/sun/star/rendering/XSpriteCanvas.hpp>
|
2020-10-31 14:32:20 +01:00
|
|
|
#include <com/sun/star/uno/XComponentContext.hpp>
|
2015-08-10 14:04:31 -05:00
|
|
|
#include <comphelper/processfactory.hxx>
|
2019-07-16 11:40:43 +01:00
|
|
|
#include <comphelper/random.hxx>
|
2015-08-10 14:04:31 -05:00
|
|
|
#include <cppuhelper/bootstrap.hxx>
|
2021-06-04 22:19:30 +02:00
|
|
|
#include <o3tl/safeint.hxx>
|
2022-05-21 17:59:07 +02:00
|
|
|
#include <utility>
|
2015-08-10 14:04:31 -05:00
|
|
|
#include <vcl/canvastools.hxx>
|
|
|
|
#include <vcl/svapp.hxx>
|
2018-12-18 18:32:13 +00:00
|
|
|
#include <vcl/vclmain.hxx>
|
|
|
|
#include <vcl/wrkwin.hxx>
|
2006-03-15 16:17:57 +00:00
|
|
|
|
|
|
|
using namespace ::com::sun::star;
|
|
|
|
|
|
|
|
static void PrintHelp()
|
|
|
|
{
|
|
|
|
fprintf( stdout, "canvasdemo - Exercise the new canvas impl\n" );
|
|
|
|
}
|
|
|
|
|
Extend loplugin:external to warn about classes
...following up on 314f15bff08b76bf96acf99141776ef64d2f1355 "Extend
loplugin:external to warn about enums".
Cases where free functions were moved into an unnamed namespace along with a
class, to not break ADL, are in:
filter/source/svg/svgexport.cxx
sc/source/filter/excel/xelink.cxx
sc/source/filter/excel/xilink.cxx
svx/source/sdr/contact/viewobjectcontactofunocontrol.cxx
All other free functions mentioning moved classes appear to be harmless and not
give rise to (silent, even) ADL breakage. (One remaining TODO in
compilerplugins/clang/external.cxx is that derived classes are not covered by
computeAffectedTypes, even though they could also be affected by ADL-breakage---
but don't seem to be in any acutal case across the code base.)
For friend declarations using elaborate type specifiers, like
class C1 {};
class C2 { friend class C1; };
* If C2 (but not C1) is moved into an unnamed namespace, the friend declaration
must be changed to not use an elaborate type specifier (i.e., "friend C1;"; see
C++17 [namespace.memdef]/3: "If the name in a friend declaration is neither
qualified nor a template-id and the declaration is a function or an
elaborated-type-specifier, the lookup to determine whether the entity has been
previously declared shall not consider any scopes outside the innermost
enclosing namespace.")
* If C1 (but not C2) is moved into an unnamed namespace, the friend declaration
must be changed too, see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71882>
"elaborated-type-specifier friend not looked up in unnamed namespace".
Apart from that, to keep changes simple and mostly mechanical (which should help
avoid regressions), out-of-line definitions of class members have been left in
the enclosing (named) namespace. But explicit specializations of class
templates had to be moved into the unnamed namespace to appease
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92598> "explicit specialization of
template from unnamed namespace using unqualified-id in enclosing namespace".
Also, accompanying declarations (of e.g. typedefs or static variables) that
could arguably be moved into the unnamed namespace too have been left alone.
And in some cases, mention of affected types in blacklists in other loplugins
needed to be adapted.
And sc/qa/unit/mark_test.cxx uses a hack of including other .cxx, one of which
is sc/source/core/data/segmenttree.cxx where e.g. ScFlatUInt16SegmentsImpl is
not moved into an unnamed namespace (because it is declared in
sc/inc/segmenttree.hxx), but its base ScFlatSegmentsImpl is. GCC warns about
such combinations with enabled-by-default -Wsubobject-linkage, but "The compiler
doesn’t give this warning for types defined in the main .C file, as those are
unlikely to have multiple definitions."
(<https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Warning-Options.html>) The
warned-about classes also don't have multiple definitions in the given test, so
disable the warning when including the .cxx.
Change-Id: Ib694094c0d8168be68f8fe90dfd0acbb66a3f1e4
Reviewed-on: https://gerrit.libreoffice.org/83239
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-19 16:32:49 +01:00
|
|
|
namespace {
|
|
|
|
|
2018-12-18 18:32:13 +00:00
|
|
|
class TestWindow : public WorkWindow
|
2006-03-15 16:17:57 +00:00
|
|
|
{
|
|
|
|
public:
|
2018-12-18 18:32:13 +00:00
|
|
|
TestWindow() : WorkWindow(nullptr, WB_APP | WB_STDWORK)
|
2006-03-15 16:17:57 +00:00
|
|
|
{
|
2018-12-18 18:32:13 +00:00
|
|
|
SetText("Canvas test");
|
2006-03-15 16:17:57 +00:00
|
|
|
SetSizePixel( Size( 600, 450 ) );
|
|
|
|
EnablePaint( true );
|
|
|
|
Show();
|
|
|
|
}
|
2018-12-18 18:32:13 +00:00
|
|
|
virtual ~TestWindow() override {}
|
|
|
|
virtual void MouseButtonUp( const MouseEvent& /*rMEvt*/ ) override
|
2006-03-15 16:17:57 +00:00
|
|
|
{
|
|
|
|
//TODO: do something cool
|
2018-12-18 18:32:13 +00:00
|
|
|
Application::Quit();
|
2006-03-15 16:17:57 +00:00
|
|
|
}
|
2018-12-18 18:32:13 +00:00
|
|
|
virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override;
|
2006-03-15 16:17:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class DemoRenderer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Size maSize;
|
|
|
|
Size maBox;
|
|
|
|
rendering::ViewState maViewState;
|
|
|
|
rendering::RenderState maRenderState;
|
|
|
|
uno::Sequence< double > maColorBlack;
|
|
|
|
uno::Sequence< double > maColorRed;
|
|
|
|
uno::Reference< rendering::XCanvas > mxCanvas;
|
|
|
|
uno::Reference< rendering::XCanvasFont > mxDefaultFont;
|
|
|
|
uno::Reference< rendering::XGraphicDevice > mxDevice;
|
|
|
|
|
|
|
|
DemoRenderer( uno::Reference< rendering::XGraphicDevice > xDevice,
|
|
|
|
uno::Reference< rendering::XCanvas > xCanvas,
|
|
|
|
Size aSize ) :
|
2008-06-24 10:07:38 +00:00
|
|
|
maSize(aSize),
|
2018-02-26 13:30:35 +02:00
|
|
|
maColorBlack( vcl::unotools::colorToStdColorSpaceSequence( COL_BLACK) ),
|
|
|
|
maColorRed( vcl::unotools::colorToStdColorSpaceSequence( COL_RED) ),
|
2008-06-24 10:07:38 +00:00
|
|
|
mxCanvas(xCanvas),
|
2022-05-21 17:59:07 +02:00
|
|
|
mxDevice(std::move( xDevice ))
|
2006-03-15 16:17:57 +00:00
|
|
|
{
|
|
|
|
// Geometry init
|
|
|
|
geometry::AffineMatrix2D aUnit( 1,0, 0,
|
|
|
|
0,1, 0 );
|
|
|
|
maViewState.AffineTransform = aUnit;
|
|
|
|
maRenderState.AffineTransform = aUnit;
|
|
|
|
maRenderState.DeviceColor = maColorBlack;
|
|
|
|
|
2016-01-04 12:37:59 +01:00
|
|
|
//I can't figure out what the compositeoperation stuff does
|
2006-03-15 16:17:57 +00:00
|
|
|
//it doesn't seem to do anything in either VCL or cairocanvas
|
|
|
|
//I was hoping that CLEAR would clear the canvas before we paint,
|
|
|
|
//but nothing changes
|
|
|
|
maRenderState.CompositeOperation = rendering::CompositeOperation::OVER;
|
|
|
|
|
2018-12-18 18:32:13 +00:00
|
|
|
maBox.setWidth(aSize.Width() / 3);
|
|
|
|
maBox.setHeight(aSize.Height() / 3);
|
2006-03-15 16:17:57 +00:00
|
|
|
|
|
|
|
lang::Locale aLocale;
|
|
|
|
rendering::FontInfo aFontInfo;
|
2013-11-15 11:05:19 +02:00
|
|
|
aFontInfo.FamilyName = "Swiss";
|
|
|
|
aFontInfo.StyleName = "SansSerif";
|
2006-03-15 16:17:57 +00:00
|
|
|
geometry::Matrix2D aFontMatrix( 1, 0,
|
|
|
|
0, 1 );
|
|
|
|
rendering::FontRequest aFontRequest( aFontInfo, 12.0, 0.0, aLocale );
|
|
|
|
uno::Sequence< beans::PropertyValue > aExtraFontProperties;
|
2019-02-08 09:29:48 +02:00
|
|
|
mxDefaultFont = xCanvas->createFont( aFontRequest, aExtraFontProperties, aFontMatrix );
|
2006-03-15 16:17:57 +00:00
|
|
|
if( !mxDefaultFont.is() )
|
|
|
|
fprintf( stderr, "Failed to create font\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
void drawGrid()
|
|
|
|
{
|
2020-10-21 09:29:45 +02:00
|
|
|
tools::Long d, dIncr = maSize.Width() / 3;
|
2006-03-15 16:17:57 +00:00
|
|
|
for ( d = 0; d <= maSize.Width(); d += dIncr )
|
|
|
|
mxCanvas->drawLine( geometry::RealPoint2D( d, 0 ),
|
|
|
|
geometry::RealPoint2D( d, maSize.Height() ),
|
|
|
|
maViewState, maRenderState );
|
|
|
|
dIncr = maSize.Height() / 3;
|
|
|
|
for ( d = 0; d <= maSize.Height(); d += dIncr )
|
|
|
|
mxCanvas->drawLine( geometry::RealPoint2D( 0, d ),
|
|
|
|
geometry::RealPoint2D( maSize.Width(), d ),
|
|
|
|
maViewState, maRenderState );
|
|
|
|
}
|
|
|
|
|
2013-02-28 19:28:03 +01:00
|
|
|
void drawStringAt( OString aString, double x, double y )
|
2006-03-15 16:17:57 +00:00
|
|
|
{
|
|
|
|
rendering::StringContext aText;
|
2014-11-06 17:24:13 +01:00
|
|
|
aText.Text = OStringToOUString( aString, RTL_TEXTENCODING_UTF8 );
|
2006-03-15 16:17:57 +00:00
|
|
|
aText.StartPosition = 0;
|
|
|
|
aText.Length = aString.getLength();
|
|
|
|
rendering::RenderState aRenderState( maRenderState );
|
|
|
|
aRenderState.AffineTransform.m02 += x;
|
|
|
|
aRenderState.AffineTransform.m12 += y;
|
|
|
|
|
|
|
|
mxCanvas->drawText( aText, mxDefaultFont, maViewState, aRenderState, 0);
|
|
|
|
}
|
|
|
|
|
2019-01-23 14:31:11 +02:00
|
|
|
void drawRect( tools::Rectangle rRect, const uno::Sequence< double > &aColor, int /*nWidth*/ )
|
2006-03-15 16:17:57 +00:00
|
|
|
{
|
2021-06-04 22:19:30 +02:00
|
|
|
uno::Sequence< uno::Sequence< geometry::RealPoint2D > > aPolys
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ o3tl::narrowing<double>(rRect.Left()), o3tl::narrowing<double>(rRect.Top()) },
|
|
|
|
{ o3tl::narrowing<double>(rRect.Left()), o3tl::narrowing<double>(rRect.Bottom()) },
|
|
|
|
{ o3tl::narrowing<double>(rRect.Right()), o3tl::narrowing<double>(rRect.Bottom()) },
|
|
|
|
{ o3tl::narrowing<double>(rRect.Right()), o3tl::narrowing<double>(rRect.Top()) }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
auto xPoly = mxDevice->createCompatibleLinePolyPolygon( aPolys );
|
2006-03-15 16:17:57 +00:00
|
|
|
xPoly->setClosed( 0, true );
|
|
|
|
|
|
|
|
rendering::RenderState aRenderState( maRenderState );
|
|
|
|
aRenderState.DeviceColor = aColor;
|
2019-07-19 09:50:11 +02:00
|
|
|
mxCanvas->drawPolyPolygon( xPoly, maViewState, aRenderState );
|
2006-03-15 16:17:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void translate( double x, double y)
|
|
|
|
{
|
|
|
|
maRenderState.AffineTransform.m02 += x;
|
|
|
|
maRenderState.AffineTransform.m12 += y;
|
|
|
|
}
|
|
|
|
|
|
|
|
void drawPolishDiamond( double center_x, double center_y)
|
|
|
|
{
|
|
|
|
const int VERTICES = 10;
|
|
|
|
const double RADIUS = 60.0;
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
rendering::RenderState maOldRenderState = maRenderState; // push
|
|
|
|
translate( center_x, center_y );
|
|
|
|
|
|
|
|
for (i = 0; i < VERTICES; i++)
|
|
|
|
{
|
2014-12-06 19:51:04 +01:00
|
|
|
double a = 2.0 * M_PI * i / VERTICES;
|
2006-03-15 16:17:57 +00:00
|
|
|
geometry::RealPoint2D aSrc( RADIUS * cos (a), RADIUS * sin (a) );
|
|
|
|
|
|
|
|
for (j = i + 1; j < VERTICES; j++)
|
|
|
|
{
|
|
|
|
a = 2.0 * M_PI * j / VERTICES;
|
|
|
|
|
|
|
|
// FIXME: set cap_style to 'ROUND'
|
|
|
|
mxCanvas->drawLine( aSrc,
|
|
|
|
geometry::RealPoint2D( RADIUS * cos (a),
|
|
|
|
RADIUS * sin (a) ),
|
|
|
|
maViewState, maRenderState );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
maRenderState = maOldRenderState; // pop
|
|
|
|
}
|
|
|
|
|
|
|
|
void drawHilbert( double anchor_x, double anchor_y )
|
|
|
|
{
|
|
|
|
const double SCALE=7.0;
|
|
|
|
const char hilbert[] = "urdrrulurulldluuruluurdrurddldrrruluurdrurddldrddlulldrdldrrurd";
|
2022-05-08 23:56:45 +05:30
|
|
|
int nLength = std::size( hilbert );
|
2006-03-15 16:17:57 +00:00
|
|
|
|
|
|
|
uno::Sequence< geometry::RealPoint2D > aPoints( nLength );
|
2021-10-28 16:12:28 +03:00
|
|
|
auto pPoints = aPoints.getArray();
|
2006-03-15 16:17:57 +00:00
|
|
|
uno::Reference< rendering::XLinePolyPolygon2D > xPoly;
|
|
|
|
|
2021-10-28 16:12:28 +03:00
|
|
|
pPoints[0] = geometry::RealPoint2D( anchor_x, anchor_y );
|
2006-03-15 16:17:57 +00:00
|
|
|
for (int i = 0; i < nLength; i++ )
|
|
|
|
{
|
|
|
|
switch( hilbert[i] )
|
|
|
|
{
|
|
|
|
case 'u':
|
2021-10-28 16:12:28 +03:00
|
|
|
pPoints[i+1] = geometry::RealPoint2D( aPoints[i].X,
|
2006-03-15 16:17:57 +00:00
|
|
|
aPoints[i].Y - SCALE );
|
|
|
|
break;
|
|
|
|
case 'd':
|
2021-10-28 16:12:28 +03:00
|
|
|
pPoints[i+1] = geometry::RealPoint2D( aPoints[i].X,
|
2006-03-15 16:17:57 +00:00
|
|
|
aPoints[i].Y + SCALE );
|
|
|
|
break;
|
|
|
|
case 'l':
|
2021-10-28 16:12:28 +03:00
|
|
|
pPoints[i+1] = geometry::RealPoint2D( aPoints[i].X - SCALE,
|
2006-03-15 16:17:57 +00:00
|
|
|
aPoints[i].Y );
|
|
|
|
break;
|
|
|
|
case 'r':
|
2021-10-28 16:12:28 +03:00
|
|
|
pPoints[i+1] = geometry::RealPoint2D( aPoints[i].X + SCALE,
|
2006-03-15 16:17:57 +00:00
|
|
|
aPoints[i].Y );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-04 22:19:30 +02:00
|
|
|
uno::Sequence< uno::Sequence< geometry::RealPoint2D > > aPolys { aPoints };
|
2006-03-15 16:17:57 +00:00
|
|
|
|
|
|
|
xPoly = mxDevice->createCompatibleLinePolyPolygon( aPolys );
|
|
|
|
xPoly->setClosed( 0, false );
|
|
|
|
|
|
|
|
rendering::RenderState aRenderState( maRenderState );
|
|
|
|
aRenderState.DeviceColor = maColorRed;
|
|
|
|
// aRenderState.DeviceColor[3] = 0.5;
|
|
|
|
rendering::StrokeAttributes aStrokeAttrs;
|
|
|
|
aStrokeAttrs.StrokeWidth = 4.0;
|
|
|
|
aStrokeAttrs.MiterLimit = 2.0; // ?
|
|
|
|
aStrokeAttrs.StartCapType = rendering::PathCapType::BUTT;
|
|
|
|
aStrokeAttrs.EndCapType = rendering::PathCapType::BUTT;
|
|
|
|
aStrokeAttrs.JoinType = rendering::PathJoinType::MITER;
|
2014-09-28 07:51:19 +02:00
|
|
|
//fprintf( stderr, "FIXME: stroking a tools::PolyPolygon doesn't show up\n" );
|
2006-03-15 16:17:57 +00:00
|
|
|
//yes it does
|
2019-07-19 09:50:11 +02:00
|
|
|
mxCanvas->strokePolyPolygon( xPoly, maViewState, aRenderState, aStrokeAttrs );
|
2006-03-15 16:17:57 +00:00
|
|
|
// FIXME: do this instead:
|
2019-07-19 09:50:11 +02:00
|
|
|
//mxCanvas->drawPolyPolygon( xPoly, maViewState, aRenderState );
|
2006-03-15 16:17:57 +00:00
|
|
|
}
|
|
|
|
|
2013-02-28 19:28:03 +01:00
|
|
|
void drawTitle( OString aTitle )
|
2006-03-15 16:17:57 +00:00
|
|
|
{
|
|
|
|
// FIXME: text anchoring to be done
|
|
|
|
double nStringWidth = aTitle.getLength() * 8.0;
|
|
|
|
drawStringAt ( aTitle, (maBox.Width() - nStringWidth) / 2, 15 );
|
|
|
|
}
|
|
|
|
|
|
|
|
void drawRectangles()
|
|
|
|
{
|
|
|
|
rendering::RenderState maOldRenderState = maRenderState; // push
|
|
|
|
|
2013-02-28 19:28:03 +01:00
|
|
|
drawTitle( OString( "Rectangles" ) );
|
2006-03-15 16:17:57 +00:00
|
|
|
|
2018-12-18 18:32:13 +00:00
|
|
|
drawRect( tools::Rectangle( 20, 30, 70, 60 ), maColorRed, 8 );
|
2006-03-15 16:17:57 +00:00
|
|
|
// color mediumseagreen, stipple fill, outline black
|
2018-12-18 18:32:13 +00:00
|
|
|
drawRect( tools::Rectangle( 90, 40, 180, 100 ), maColorBlack, 4 );
|
2006-03-15 16:17:57 +00:00
|
|
|
// color steelblue, filled, no outline
|
2018-12-18 18:32:13 +00:00
|
|
|
drawRect( tools::Rectangle( 10, 80, 80, 140 ), maColorBlack, 1 );
|
2006-03-15 16:17:57 +00:00
|
|
|
|
|
|
|
maRenderState = maOldRenderState; // pop
|
|
|
|
}
|
|
|
|
|
|
|
|
void drawEllipses()
|
|
|
|
{
|
|
|
|
rendering::RenderState maOldRenderState = maRenderState; // push
|
|
|
|
translate( maBox.Width(), 0.0 );
|
|
|
|
|
2013-02-28 19:28:03 +01:00
|
|
|
drawTitle( OString( "Ellipses" ) );
|
2006-03-15 16:17:57 +00:00
|
|
|
|
2006-04-04 14:37:19 +00:00
|
|
|
const basegfx::B2DPoint aCenter( maBox.Width()*.5,
|
|
|
|
maBox.Height()*.5 );
|
|
|
|
const basegfx::B2DPoint aRadii( maBox.Width()*.3,
|
|
|
|
maBox.Height()*.3 );
|
|
|
|
const basegfx::B2DPolygon& rEllipse(
|
2017-09-22 14:12:07 +03:00
|
|
|
basegfx::utils::createPolygonFromEllipse( aCenter,
|
2006-04-04 14:37:19 +00:00
|
|
|
aRadii.getX(),
|
|
|
|
aRadii.getY() ));
|
|
|
|
|
|
|
|
uno::Reference< rendering::XPolyPolygon2D > xPoly(
|
|
|
|
basegfx::unotools::xPolyPolygonFromB2DPolygon(mxDevice,
|
|
|
|
rEllipse) );
|
|
|
|
|
|
|
|
rendering::StrokeAttributes aStrokeAttrs;
|
|
|
|
aStrokeAttrs.StrokeWidth = 4.0;
|
|
|
|
aStrokeAttrs.MiterLimit = 2.0; // ?
|
|
|
|
aStrokeAttrs.StartCapType = rendering::PathCapType::BUTT;
|
|
|
|
aStrokeAttrs.EndCapType = rendering::PathCapType::BUTT;
|
|
|
|
aStrokeAttrs.JoinType = rendering::PathJoinType::MITER;
|
|
|
|
mxCanvas->strokePolyPolygon( xPoly, maViewState, maRenderState, aStrokeAttrs );
|
2006-03-15 16:17:57 +00:00
|
|
|
|
|
|
|
maRenderState = maOldRenderState; // pop
|
|
|
|
}
|
|
|
|
|
|
|
|
void drawText()
|
|
|
|
{
|
|
|
|
rendering::RenderState maOldRenderState = maRenderState; // push
|
|
|
|
translate( maBox.Width() * 2.0, 0.0 );
|
|
|
|
|
2013-02-28 19:28:03 +01:00
|
|
|
drawTitle( OString( "Text" ) );
|
2006-03-15 16:17:57 +00:00
|
|
|
|
2006-04-04 14:37:19 +00:00
|
|
|
translate( 0.0,
|
|
|
|
maBox.Height() * .5 );
|
2013-02-28 19:28:03 +01:00
|
|
|
drawTitle( OString( "This is lame" ) );
|
2006-04-04 14:37:19 +00:00
|
|
|
|
2006-03-15 16:17:57 +00:00
|
|
|
maRenderState = maOldRenderState; // pop
|
|
|
|
}
|
|
|
|
|
|
|
|
void drawImages()
|
|
|
|
{
|
|
|
|
rendering::RenderState maOldRenderState = maRenderState; // push
|
|
|
|
translate( 0.0, maBox.Height() );
|
|
|
|
|
2013-02-28 19:28:03 +01:00
|
|
|
drawTitle( OString( "Images" ) );
|
2006-03-15 16:17:57 +00:00
|
|
|
|
|
|
|
uno::Reference< rendering::XBitmap > xBitmap(mxCanvas, uno::UNO_QUERY);
|
2008-06-24 10:07:38 +00:00
|
|
|
|
|
|
|
if( !xBitmap.is() )
|
|
|
|
return;
|
2006-04-04 14:37:19 +00:00
|
|
|
|
|
|
|
translate( maBox.Width()*0.1, maBox.Height()*0.2 );
|
|
|
|
maRenderState.AffineTransform.m00 *= 4.0/15;
|
|
|
|
maRenderState.AffineTransform.m11 *= 3.0/15;
|
|
|
|
|
|
|
|
mxCanvas->drawBitmap(xBitmap, maViewState, maRenderState);
|
|
|
|
|
|
|
|
// uno::Reference< rendering::XBitmap > xBitmap2( xBitmap->getScaledBitmap(geometry::RealSize2D(48, 48), false) );
|
|
|
|
// mxCanvas->drawBitmap(xBitmap2, maViewState, maRenderState); //yes, but where?
|
2006-03-15 16:17:57 +00:00
|
|
|
//cairo-canvas says:
|
|
|
|
//called CanvasHelper::getScaledBitmap, we return NULL, TODO
|
2015-07-21 12:16:45 +02:00
|
|
|
//Exception 'BitmapEx vclcanvas::tools::bitmapExFromXBitmap(const css::uno::Reference<css::rendering::XBitmap>&),
|
2006-03-15 16:17:57 +00:00
|
|
|
//bitmapExFromXBitmap(): could not extract BitmapEx' thrown
|
2014-02-25 17:46:23 +01:00
|
|
|
|
2006-03-15 16:17:57 +00:00
|
|
|
//vcl-canvas says:
|
2015-07-21 12:16:45 +02:00
|
|
|
//Exception 'BitmapEx vclcanvas::tools::bitmapExFromXBitmap(const css::uno::Reference<css::rendering::XBitmap>&),
|
2006-03-15 16:17:57 +00:00
|
|
|
//bitmapExFromXBitmap(): could not extract bitmap' thrown
|
|
|
|
// Thorsten says that this is a bug, and Thorsten never lies.
|
|
|
|
|
|
|
|
maRenderState = maOldRenderState; // pop
|
|
|
|
}
|
|
|
|
|
|
|
|
void drawLines()
|
|
|
|
{
|
|
|
|
rendering::RenderState maOldRenderState = maRenderState; // push
|
|
|
|
translate( maBox.Width(), maBox.Height() );
|
|
|
|
|
2013-02-28 19:28:03 +01:00
|
|
|
drawTitle( OString( "Lines" ) );
|
2006-03-15 16:17:57 +00:00
|
|
|
|
|
|
|
drawPolishDiamond( 70.0, 80.0 );
|
|
|
|
drawHilbert( 140.0, 140.0 );
|
|
|
|
|
|
|
|
maRenderState = maOldRenderState; // pop
|
|
|
|
}
|
|
|
|
|
|
|
|
void drawCurves()
|
|
|
|
{
|
|
|
|
rendering::RenderState maOldRenderState = maRenderState; // push
|
|
|
|
translate( maBox.Width() * 2.0, maBox.Height() );
|
|
|
|
|
2013-02-28 19:28:03 +01:00
|
|
|
drawTitle( OString( "Curves" ) );
|
2006-03-15 16:17:57 +00:00
|
|
|
|
2006-04-04 14:37:19 +00:00
|
|
|
translate( maBox.Width() * .5, maBox.Height() * .5 );
|
|
|
|
|
2006-03-15 16:17:57 +00:00
|
|
|
const double r= 30.0;
|
|
|
|
const int num_curves = 3;
|
|
|
|
|
|
|
|
//hacky hack hack
|
|
|
|
uno::Sequence< geometry::RealBezierSegment2D > aBeziers (num_curves);
|
2021-10-28 16:12:28 +03:00
|
|
|
auto pBeziers = aBeziers.getArray();
|
2006-03-15 16:17:57 +00:00
|
|
|
uno::Reference< rendering::XBezierPolyPolygon2D > xPoly;
|
|
|
|
|
|
|
|
for (int i= 0; i < num_curves; i++)
|
2021-10-28 16:12:28 +03:00
|
|
|
pBeziers[i]= geometry::RealBezierSegment2D( r * cos(i*2*M_PI/num_curves), //Px
|
2006-03-15 16:17:57 +00:00
|
|
|
r * sin(i*2*M_PI/num_curves), //py
|
|
|
|
r * 2 * cos((i*2*M_PI + 2*M_PI)/num_curves), //C1x
|
|
|
|
r * 2 * sin((i*2*M_PI + 2*M_PI)/num_curves), //C1y
|
|
|
|
r * 2 * cos((i*2*M_PI + 2*M_PI)/num_curves), //C2x
|
|
|
|
r * 2 * sin((i*2*M_PI + 2*M_PI)/num_curves)); //C2y
|
2021-06-04 22:19:30 +02:00
|
|
|
uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > > aPolys { aBeziers };
|
2006-03-15 16:17:57 +00:00
|
|
|
xPoly = mxDevice->createCompatibleBezierPolyPolygon(aPolys);
|
|
|
|
xPoly->setClosed( 0, true );
|
|
|
|
//uno::Reference< rendering::XBezierPolyPolygon2D> xPP( xPoly, uno::UNO_QUERY );
|
2016-01-04 12:37:59 +01:00
|
|
|
//compiles, but totally screws up. I think it is interpreting the bezier as a line
|
2006-03-15 16:17:57 +00:00
|
|
|
|
|
|
|
rendering::StrokeAttributes aStrokeAttrs;
|
|
|
|
aStrokeAttrs.StrokeWidth = 4.0;
|
|
|
|
aStrokeAttrs.MiterLimit = 2.0; // ?
|
|
|
|
aStrokeAttrs.StartCapType = rendering::PathCapType::BUTT;
|
|
|
|
aStrokeAttrs.EndCapType = rendering::PathCapType::BUTT;
|
|
|
|
aStrokeAttrs.JoinType = rendering::PathJoinType::MITER;
|
2019-07-19 09:50:11 +02:00
|
|
|
mxCanvas->strokePolyPolygon( xPoly, maViewState, maRenderState, aStrokeAttrs );
|
2006-03-15 16:17:57 +00:00
|
|
|
//you can't draw a BezierPolyPolygon2D with this, even though it is derived from it
|
2019-07-19 09:50:11 +02:00
|
|
|
//mxCanvas->drawPolyPolygon( xPoly, maViewState, maRenderState );
|
2006-03-15 16:17:57 +00:00
|
|
|
|
|
|
|
maRenderState = maOldRenderState; // pop
|
|
|
|
}
|
|
|
|
|
2019-07-16 11:40:43 +01:00
|
|
|
double gimmerand()
|
2006-03-15 16:17:57 +00:00
|
|
|
{
|
2019-07-16 11:40:43 +01:00
|
|
|
return comphelper::rng::uniform_real_distribution(0, 100);
|
2006-03-15 16:17:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void drawArcs()
|
|
|
|
{
|
|
|
|
rendering::RenderState maOldRenderState = maRenderState; // push
|
|
|
|
translate( 0.0, maBox.Height() * 2.0 );
|
|
|
|
|
2013-02-28 19:28:03 +01:00
|
|
|
drawTitle( OString( "Arcs" ) );
|
2006-03-15 16:17:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
//begin hacks
|
|
|
|
//This stuff doesn't belong here, but probably in curves
|
|
|
|
//This stuff doesn't work in VCL b/c vcl doesn't do beziers
|
2014-04-29 19:05:05 +00:00
|
|
|
//Hah! Every time the window redraws, we do this
|
2006-03-15 16:17:57 +00:00
|
|
|
double bx;
|
|
|
|
double by;
|
|
|
|
bx= gimmerand();
|
|
|
|
by= gimmerand();
|
|
|
|
|
|
|
|
for (int i= 0; i < 1; i++)
|
|
|
|
{
|
2015-02-14 00:31:54 +02:00
|
|
|
double ax;
|
|
|
|
double ay;
|
2006-03-15 16:17:57 +00:00
|
|
|
//point a= point b;
|
|
|
|
ax= bx;
|
|
|
|
ay= by;
|
|
|
|
//point b= rand;
|
|
|
|
bx= gimmerand();
|
|
|
|
by= gimmerand();
|
|
|
|
double c1x= gimmerand();
|
|
|
|
double c1y= gimmerand();
|
2008-06-24 10:07:38 +00:00
|
|
|
double c2x= gimmerand();
|
|
|
|
double c2y= gimmerand();
|
2006-03-15 16:17:57 +00:00
|
|
|
maRenderState.DeviceColor = maColorRed;
|
|
|
|
mxCanvas->drawLine(geometry::RealPoint2D(ax, ay), geometry::RealPoint2D(c1x, c1y), maViewState, maRenderState);
|
2008-06-24 10:07:38 +00:00
|
|
|
mxCanvas->drawLine(geometry::RealPoint2D(c1x, c1y), geometry::RealPoint2D(c2x, c2y), maViewState, maRenderState);
|
2006-03-15 16:17:57 +00:00
|
|
|
mxCanvas->drawLine(geometry::RealPoint2D(bx, by), geometry::RealPoint2D(c2x, c2y), maViewState, maRenderState);
|
|
|
|
//draw from a to b
|
|
|
|
geometry::RealBezierSegment2D aBezierSegment(
|
|
|
|
ax, //Px
|
|
|
|
ay, //Py
|
|
|
|
c1x,
|
2008-06-24 10:07:38 +00:00
|
|
|
c1x,
|
2006-03-15 16:17:57 +00:00
|
|
|
c2x,
|
|
|
|
c2y
|
|
|
|
);
|
|
|
|
geometry::RealPoint2D aEndPoint(bx, by);
|
|
|
|
maRenderState.DeviceColor = maColorBlack;
|
|
|
|
mxCanvas->drawBezier(
|
|
|
|
aBezierSegment,
|
|
|
|
aEndPoint,
|
|
|
|
maViewState, maRenderState );
|
|
|
|
}
|
|
|
|
maRenderState = maOldRenderState; // pop
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void drawRegularPolygon(double centerx, double centery, int sides, double r)
|
|
|
|
{
|
|
|
|
//hacky hack hack
|
|
|
|
uno::Sequence< geometry::RealPoint2D > aPoints (sides);
|
2021-10-28 16:12:28 +03:00
|
|
|
auto pPoints = aPoints.getArray();
|
2006-03-15 16:17:57 +00:00
|
|
|
uno::Reference< rendering::XLinePolyPolygon2D > xPoly;
|
|
|
|
|
|
|
|
for (int i= 0; i < sides; i++)
|
|
|
|
{
|
2021-10-28 16:12:28 +03:00
|
|
|
pPoints[i]= geometry::RealPoint2D( centerx + r * cos(i*2 * M_PI/sides),
|
2006-03-15 16:17:57 +00:00
|
|
|
centery + r * sin(i*2 * M_PI/sides));
|
|
|
|
}
|
2021-06-04 22:19:30 +02:00
|
|
|
uno::Sequence< uno::Sequence< geometry::RealPoint2D > > aPolys { aPoints };
|
2006-03-15 16:17:57 +00:00
|
|
|
xPoly = mxDevice->createCompatibleLinePolyPolygon( aPolys );
|
|
|
|
xPoly->setClosed( 0, true );
|
|
|
|
rendering::RenderState aRenderState( maRenderState );
|
|
|
|
aRenderState.DeviceColor = maColorRed;
|
2019-07-19 09:50:11 +02:00
|
|
|
mxCanvas->drawPolyPolygon( xPoly, maViewState, aRenderState);
|
|
|
|
mxCanvas->fillPolyPolygon( xPoly,
|
2006-03-15 16:17:57 +00:00
|
|
|
maViewState,
|
|
|
|
aRenderState );
|
|
|
|
}
|
|
|
|
|
|
|
|
void drawPolygons()
|
|
|
|
{
|
|
|
|
rendering::RenderState maOldRenderState = maRenderState; // push
|
|
|
|
translate( maBox.Width() * 1.0, maBox.Height() * 2.0 );
|
|
|
|
|
2020-08-17 17:54:38 +02:00
|
|
|
drawTitle( OString( "Polygons" ) );
|
2006-03-15 16:17:57 +00:00
|
|
|
|
|
|
|
int sides= 3;
|
|
|
|
for (int i= 1; i <= 4; i++)
|
|
|
|
{
|
|
|
|
drawRegularPolygon(35*i, 35, sides, 15);
|
|
|
|
sides++;
|
|
|
|
}
|
|
|
|
|
|
|
|
maRenderState = maOldRenderState; // pop
|
|
|
|
}
|
|
|
|
|
|
|
|
void drawWidgets() // FIXME: prolly makes no sense
|
|
|
|
{
|
|
|
|
rendering::RenderState maOldRenderState = maRenderState; // push
|
|
|
|
translate( maBox.Width() * 2.0, maBox.Height() * 2.0 );
|
|
|
|
|
2013-02-28 19:28:03 +01:00
|
|
|
drawTitle( OString( "Widgets" ) );
|
2006-03-15 16:17:57 +00:00
|
|
|
|
|
|
|
maRenderState = maOldRenderState; // pop
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
Extend loplugin:external to warn about classes
...following up on 314f15bff08b76bf96acf99141776ef64d2f1355 "Extend
loplugin:external to warn about enums".
Cases where free functions were moved into an unnamed namespace along with a
class, to not break ADL, are in:
filter/source/svg/svgexport.cxx
sc/source/filter/excel/xelink.cxx
sc/source/filter/excel/xilink.cxx
svx/source/sdr/contact/viewobjectcontactofunocontrol.cxx
All other free functions mentioning moved classes appear to be harmless and not
give rise to (silent, even) ADL breakage. (One remaining TODO in
compilerplugins/clang/external.cxx is that derived classes are not covered by
computeAffectedTypes, even though they could also be affected by ADL-breakage---
but don't seem to be in any acutal case across the code base.)
For friend declarations using elaborate type specifiers, like
class C1 {};
class C2 { friend class C1; };
* If C2 (but not C1) is moved into an unnamed namespace, the friend declaration
must be changed to not use an elaborate type specifier (i.e., "friend C1;"; see
C++17 [namespace.memdef]/3: "If the name in a friend declaration is neither
qualified nor a template-id and the declaration is a function or an
elaborated-type-specifier, the lookup to determine whether the entity has been
previously declared shall not consider any scopes outside the innermost
enclosing namespace.")
* If C1 (but not C2) is moved into an unnamed namespace, the friend declaration
must be changed too, see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71882>
"elaborated-type-specifier friend not looked up in unnamed namespace".
Apart from that, to keep changes simple and mostly mechanical (which should help
avoid regressions), out-of-line definitions of class members have been left in
the enclosing (named) namespace. But explicit specializations of class
templates had to be moved into the unnamed namespace to appease
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92598> "explicit specialization of
template from unnamed namespace using unqualified-id in enclosing namespace".
Also, accompanying declarations (of e.g. typedefs or static variables) that
could arguably be moved into the unnamed namespace too have been left alone.
And in some cases, mention of affected types in blacklists in other loplugins
needed to be adapted.
And sc/qa/unit/mark_test.cxx uses a hack of including other .cxx, one of which
is sc/source/core/data/segmenttree.cxx where e.g. ScFlatUInt16SegmentsImpl is
not moved into an unnamed namespace (because it is declared in
sc/inc/segmenttree.hxx), but its base ScFlatSegmentsImpl is. GCC warns about
such combinations with enabled-by-default -Wsubobject-linkage, but "The compiler
doesn’t give this warning for types defined in the main .C file, as those are
unlikely to have multiple definitions."
(<https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Warning-Options.html>) The
warned-about classes also don't have multiple definitions in the given test, so
disable the warning when including the .cxx.
Change-Id: Ib694094c0d8168be68f8fe90dfd0acbb66a3f1e4
Reviewed-on: https://gerrit.libreoffice.org/83239
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-19 16:32:49 +01:00
|
|
|
}
|
2006-03-15 16:17:57 +00:00
|
|
|
|
2018-12-18 18:32:13 +00:00
|
|
|
void TestWindow::Paint(vcl::RenderContext&, const tools::Rectangle&)
|
2006-03-15 16:17:57 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-01-18 18:27:19 +02:00
|
|
|
uno::Reference< rendering::XCanvas > xVDevCanvas( GetOutDev()->GetCanvas(),
|
2019-05-10 10:13:12 +02:00
|
|
|
uno::UNO_SET_THROW );
|
2008-06-24 10:07:38 +00:00
|
|
|
uno::Reference< rendering::XGraphicDevice > xVDevDevice( xVDevCanvas->getDevice(),
|
2019-05-10 10:13:12 +02:00
|
|
|
uno::UNO_SET_THROW );
|
2018-12-18 18:32:13 +00:00
|
|
|
DemoRenderer aVDevRenderer( xVDevDevice, xVDevCanvas, GetSizePixel());
|
2008-06-24 10:07:38 +00:00
|
|
|
xVDevCanvas->clear();
|
|
|
|
aVDevRenderer.drawGrid();
|
|
|
|
aVDevRenderer.drawRectangles();
|
|
|
|
aVDevRenderer.drawEllipses();
|
|
|
|
aVDevRenderer.drawText();
|
|
|
|
aVDevRenderer.drawLines();
|
|
|
|
aVDevRenderer.drawCurves();
|
|
|
|
aVDevRenderer.drawArcs();
|
|
|
|
aVDevRenderer.drawPolygons();
|
|
|
|
|
2021-01-18 18:27:19 +02:00
|
|
|
uno::Reference< rendering::XCanvas > xCanvas( GetOutDev()->GetSpriteCanvas(),
|
2008-06-24 10:07:38 +00:00
|
|
|
uno::UNO_QUERY_THROW );
|
2006-03-15 16:17:57 +00:00
|
|
|
uno::Reference< rendering::XGraphicDevice > xDevice( xCanvas->getDevice(),
|
2019-05-10 10:13:12 +02:00
|
|
|
uno::UNO_SET_THROW );
|
2006-03-15 16:17:57 +00:00
|
|
|
|
|
|
|
DemoRenderer aRenderer( xDevice, xCanvas, GetSizePixel() );
|
2008-06-24 10:07:38 +00:00
|
|
|
xCanvas->clear();
|
2006-03-15 16:17:57 +00:00
|
|
|
aRenderer.drawGrid();
|
|
|
|
aRenderer.drawRectangles();
|
|
|
|
aRenderer.drawEllipses();
|
|
|
|
aRenderer.drawText();
|
|
|
|
aRenderer.drawLines();
|
|
|
|
aRenderer.drawCurves();
|
|
|
|
aRenderer.drawArcs();
|
|
|
|
aRenderer.drawPolygons();
|
|
|
|
aRenderer.drawWidgets();
|
2006-04-04 14:37:19 +00:00
|
|
|
aRenderer.drawImages();
|
2006-03-15 16:17:57 +00:00
|
|
|
|
2008-06-24 10:07:38 +00:00
|
|
|
// check whether virdev actually contained something
|
|
|
|
uno::Reference< rendering::XBitmap > xBitmap(xVDevCanvas, uno::UNO_QUERY);
|
|
|
|
if( !xBitmap.is() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
aRenderer.maRenderState.AffineTransform.m02 += 100;
|
|
|
|
aRenderer.maRenderState.AffineTransform.m12 += 100;
|
|
|
|
xCanvas->drawBitmap(xBitmap, aRenderer.maViewState, aRenderer.maRenderState);
|
|
|
|
|
2006-04-04 14:37:19 +00:00
|
|
|
uno::Reference< rendering::XSpriteCanvas > xSpriteCanvas( xCanvas,
|
2008-06-24 10:07:38 +00:00
|
|
|
uno::UNO_QUERY );
|
|
|
|
if( xSpriteCanvas.is() )
|
2018-12-18 18:32:13 +00:00
|
|
|
xSpriteCanvas->updateScreen( true ); // without
|
2008-06-24 10:07:38 +00:00
|
|
|
// updateScreen(),
|
|
|
|
// nothing is
|
|
|
|
// visible
|
2006-03-15 16:17:57 +00:00
|
|
|
}
|
|
|
|
catch (const uno::Exception &e)
|
|
|
|
{
|
|
|
|
fprintf( stderr, "Exception '%s' thrown\n" ,
|
2013-02-28 19:28:03 +01:00
|
|
|
OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
|
2006-03-15 16:17:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Extend loplugin:external to warn about classes
...following up on 314f15bff08b76bf96acf99141776ef64d2f1355 "Extend
loplugin:external to warn about enums".
Cases where free functions were moved into an unnamed namespace along with a
class, to not break ADL, are in:
filter/source/svg/svgexport.cxx
sc/source/filter/excel/xelink.cxx
sc/source/filter/excel/xilink.cxx
svx/source/sdr/contact/viewobjectcontactofunocontrol.cxx
All other free functions mentioning moved classes appear to be harmless and not
give rise to (silent, even) ADL breakage. (One remaining TODO in
compilerplugins/clang/external.cxx is that derived classes are not covered by
computeAffectedTypes, even though they could also be affected by ADL-breakage---
but don't seem to be in any acutal case across the code base.)
For friend declarations using elaborate type specifiers, like
class C1 {};
class C2 { friend class C1; };
* If C2 (but not C1) is moved into an unnamed namespace, the friend declaration
must be changed to not use an elaborate type specifier (i.e., "friend C1;"; see
C++17 [namespace.memdef]/3: "If the name in a friend declaration is neither
qualified nor a template-id and the declaration is a function or an
elaborated-type-specifier, the lookup to determine whether the entity has been
previously declared shall not consider any scopes outside the innermost
enclosing namespace.")
* If C1 (but not C2) is moved into an unnamed namespace, the friend declaration
must be changed too, see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71882>
"elaborated-type-specifier friend not looked up in unnamed namespace".
Apart from that, to keep changes simple and mostly mechanical (which should help
avoid regressions), out-of-line definitions of class members have been left in
the enclosing (named) namespace. But explicit specializations of class
templates had to be moved into the unnamed namespace to appease
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92598> "explicit specialization of
template from unnamed namespace using unqualified-id in enclosing namespace".
Also, accompanying declarations (of e.g. typedefs or static variables) that
could arguably be moved into the unnamed namespace too have been left alone.
And in some cases, mention of affected types in blacklists in other loplugins
needed to be adapted.
And sc/qa/unit/mark_test.cxx uses a hack of including other .cxx, one of which
is sc/source/core/data/segmenttree.cxx where e.g. ScFlatUInt16SegmentsImpl is
not moved into an unnamed namespace (because it is declared in
sc/inc/segmenttree.hxx), but its base ScFlatSegmentsImpl is. GCC warns about
such combinations with enabled-by-default -Wsubobject-linkage, but "The compiler
doesn’t give this warning for types defined in the main .C file, as those are
unlikely to have multiple definitions."
(<https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Warning-Options.html>) The
warned-about classes also don't have multiple definitions in the given test, so
disable the warning when including the .cxx.
Change-Id: Ib694094c0d8168be68f8fe90dfd0acbb66a3f1e4
Reviewed-on: https://gerrit.libreoffice.org/83239
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-19 16:32:49 +01:00
|
|
|
namespace {
|
|
|
|
|
2018-12-18 18:32:13 +00:00
|
|
|
class DemoApp : public Application
|
2006-03-15 16:17:57 +00:00
|
|
|
{
|
2018-12-18 18:32:13 +00:00
|
|
|
public:
|
|
|
|
virtual int Main() override;
|
|
|
|
virtual void Exception(ExceptionCategory nCategory) override;
|
2006-03-15 16:17:57 +00:00
|
|
|
|
2018-12-18 18:32:13 +00:00
|
|
|
protected:
|
|
|
|
void Init() override;
|
|
|
|
void DeInit() override;
|
|
|
|
};
|
|
|
|
|
Extend loplugin:external to warn about classes
...following up on 314f15bff08b76bf96acf99141776ef64d2f1355 "Extend
loplugin:external to warn about enums".
Cases where free functions were moved into an unnamed namespace along with a
class, to not break ADL, are in:
filter/source/svg/svgexport.cxx
sc/source/filter/excel/xelink.cxx
sc/source/filter/excel/xilink.cxx
svx/source/sdr/contact/viewobjectcontactofunocontrol.cxx
All other free functions mentioning moved classes appear to be harmless and not
give rise to (silent, even) ADL breakage. (One remaining TODO in
compilerplugins/clang/external.cxx is that derived classes are not covered by
computeAffectedTypes, even though they could also be affected by ADL-breakage---
but don't seem to be in any acutal case across the code base.)
For friend declarations using elaborate type specifiers, like
class C1 {};
class C2 { friend class C1; };
* If C2 (but not C1) is moved into an unnamed namespace, the friend declaration
must be changed to not use an elaborate type specifier (i.e., "friend C1;"; see
C++17 [namespace.memdef]/3: "If the name in a friend declaration is neither
qualified nor a template-id and the declaration is a function or an
elaborated-type-specifier, the lookup to determine whether the entity has been
previously declared shall not consider any scopes outside the innermost
enclosing namespace.")
* If C1 (but not C2) is moved into an unnamed namespace, the friend declaration
must be changed too, see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71882>
"elaborated-type-specifier friend not looked up in unnamed namespace".
Apart from that, to keep changes simple and mostly mechanical (which should help
avoid regressions), out-of-line definitions of class members have been left in
the enclosing (named) namespace. But explicit specializations of class
templates had to be moved into the unnamed namespace to appease
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92598> "explicit specialization of
template from unnamed namespace using unqualified-id in enclosing namespace".
Also, accompanying declarations (of e.g. typedefs or static variables) that
could arguably be moved into the unnamed namespace too have been left alone.
And in some cases, mention of affected types in blacklists in other loplugins
needed to be adapted.
And sc/qa/unit/mark_test.cxx uses a hack of including other .cxx, one of which
is sc/source/core/data/segmenttree.cxx where e.g. ScFlatUInt16SegmentsImpl is
not moved into an unnamed namespace (because it is declared in
sc/inc/segmenttree.hxx), but its base ScFlatSegmentsImpl is. GCC warns about
such combinations with enabled-by-default -Wsubobject-linkage, but "The compiler
doesn’t give this warning for types defined in the main .C file, as those are
unlikely to have multiple definitions."
(<https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Warning-Options.html>) The
warned-about classes also don't have multiple definitions in the given test, so
disable the warning when including the .cxx.
Change-Id: Ib694094c0d8168be68f8fe90dfd0acbb66a3f1e4
Reviewed-on: https://gerrit.libreoffice.org/83239
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-19 16:32:49 +01:00
|
|
|
}
|
|
|
|
|
2018-12-18 18:32:13 +00:00
|
|
|
int DemoApp::Main()
|
2006-03-15 16:17:57 +00:00
|
|
|
{
|
|
|
|
bool bHelp = false;
|
|
|
|
|
2018-12-18 18:32:13 +00:00
|
|
|
for( unsigned int i = 0; i < GetCommandLineParamCount(); i++ )
|
2006-03-15 16:17:57 +00:00
|
|
|
{
|
2013-02-28 19:28:03 +01:00
|
|
|
OUString aParam = GetCommandLineParam( i );
|
2006-03-15 16:17:57 +00:00
|
|
|
|
2012-04-06 19:49:53 +02:00
|
|
|
if( aParam == "--help" || aParam == "-h" )
|
|
|
|
bHelp = true;
|
2006-03-15 16:17:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( bHelp )
|
|
|
|
{
|
|
|
|
PrintHelp();
|
2018-12-18 18:32:13 +00:00
|
|
|
return 1;
|
2006-03-15 16:17:57 +00:00
|
|
|
}
|
|
|
|
|
2018-12-18 18:32:13 +00:00
|
|
|
ScopedVclPtr<TestWindow> aWindow = VclPtr<TestWindow>::Create();
|
|
|
|
aWindow->Show();
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2018-12-18 18:32:13 +00:00
|
|
|
Application::Execute();
|
|
|
|
return 0;
|
|
|
|
}
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2020-08-16 09:42:27 +02:00
|
|
|
void DemoApp::Exception( ExceptionCategory )
|
2018-12-18 18:32:13 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void DemoApp::Init()
|
|
|
|
{
|
|
|
|
try
|
2006-04-04 14:37:19 +00:00
|
|
|
{
|
2018-12-18 18:32:13 +00:00
|
|
|
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);
|
2006-04-04 14:37:19 +00:00
|
|
|
}
|
2018-12-18 18:32:13 +00:00
|
|
|
catch (const uno::Exception &e)
|
2006-04-04 14:37:19 +00:00
|
|
|
{
|
2018-12-18 18:32:13 +00:00
|
|
|
Application::Abort("Bootstrap exception " + e.Message);
|
2006-04-04 14:37:19 +00:00
|
|
|
}
|
2018-12-18 18:32:13 +00:00
|
|
|
}
|
2006-04-04 14:37:19 +00:00
|
|
|
|
2018-12-18 18:32:13 +00:00
|
|
|
void DemoApp::DeInit()
|
|
|
|
{
|
|
|
|
uno::Reference< lang::XComponent >(
|
|
|
|
comphelper::getProcessComponentContext(),
|
|
|
|
uno::UNO_QUERY_THROW)-> dispose();
|
|
|
|
::comphelper::setProcessServiceFactory(nullptr);
|
2006-03-15 16:17:57 +00:00
|
|
|
}
|
|
|
|
|
2018-12-18 18:32:13 +00:00
|
|
|
void vclmain::createApplication()
|
|
|
|
{
|
|
|
|
static DemoApp aApp;
|
|
|
|
}
|
2006-03-15 16:17:57 +00:00
|
|
|
|
|
|
|
// TODO
|
2015-10-02 10:52:20 +02:00
|
|
|
// - bouncing clip-rectangle mode - bounce a clip-rect around the window...
|
2006-03-15 16:17:57 +00:00
|
|
|
// - complete all of pre-existing canvas bits
|
2015-10-02 10:52:20 +02:00
|
|
|
// - affine transform tweakage...
|
2006-03-15 16:17:57 +00:00
|
|
|
|
2010-10-14 08:27:31 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|