xref: /aoo41x/main/canvas/workben/canvasdemo.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir 
29*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
30*cdf0e10cSrcweir #include "precompiled_canvas.hxx"
31*cdf0e10cSrcweir // This code strongly inspired by Miguel / Federico's Gnome Canvas demo code.
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
34*cdf0e10cSrcweir #include <comphelper/regpathhelper.hxx>
35*cdf0e10cSrcweir #include <cppuhelper/servicefactory.hxx>
36*cdf0e10cSrcweir #include <cppuhelper/bootstrap.hxx>
37*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp>
39*cdf0e10cSrcweir #include <com/sun/star/registry/XSimpleRegistry.hpp>
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir #include <ucbhelper/contentbroker.hxx>
42*cdf0e10cSrcweir #include <ucbhelper/configurationkeys.hxx>
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx>
45*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx>
46*cdf0e10cSrcweir #include <basegfx/tools/canvastools.hxx>
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir #include <vcl/window.hxx>
49*cdf0e10cSrcweir #include <vcl/virdev.hxx>
50*cdf0e10cSrcweir #include <vcl/svapp.hxx>
51*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
52*cdf0e10cSrcweir #include <vcl/unowrap.hxx>
53*cdf0e10cSrcweir #include <vcl/canvastools.hxx>
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir #include <rtl/bootstrap.hxx>
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir #include <com/sun/star/rendering/XCanvas.hpp>
58*cdf0e10cSrcweir #include <com/sun/star/rendering/FillRule.hpp>
59*cdf0e10cSrcweir #include <com/sun/star/rendering/ViewState.hpp>
60*cdf0e10cSrcweir #include <com/sun/star/rendering/RenderState.hpp>
61*cdf0e10cSrcweir #include <com/sun/star/rendering/PathCapType.hpp>
62*cdf0e10cSrcweir #include <com/sun/star/rendering/PathJoinType.hpp>
63*cdf0e10cSrcweir #include <com/sun/star/rendering/XSpriteCanvas.hpp>
64*cdf0e10cSrcweir #include <com/sun/star/rendering/XGraphicDevice.hpp>
65*cdf0e10cSrcweir #include <com/sun/star/rendering/CompositeOperation.hpp>
66*cdf0e10cSrcweir #include <com/sun/star/rendering/XBitmap.hpp>
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir #include <stdio.h>
69*cdf0e10cSrcweir #include <unistd.h>
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir // never import whole leaf namespaces, since this will result in
73*cdf0e10cSrcweir // absolutely weird effects during (Koenig) name lookup
74*cdf0e10cSrcweir using namespace ::com::sun::star;
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir class DemoApp : public Application
78*cdf0e10cSrcweir {
79*cdf0e10cSrcweir public:
80*cdf0e10cSrcweir 	virtual void Main();
81*cdf0e10cSrcweir 	virtual USHORT	Exception( USHORT nError );
82*cdf0e10cSrcweir };
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir static void PrintHelp()
85*cdf0e10cSrcweir {
86*cdf0e10cSrcweir 	fprintf( stdout, "canvasdemo - Exercise the new canvas impl\n" );
87*cdf0e10cSrcweir }
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir class TestWindow : public Dialog
90*cdf0e10cSrcweir {
91*cdf0e10cSrcweir 	public:
92*cdf0e10cSrcweir 		TestWindow() : Dialog( (Window *) NULL )
93*cdf0e10cSrcweir 		{
94*cdf0e10cSrcweir 			SetText( rtl::OUString::createFromAscii( "Canvas test" ) );
95*cdf0e10cSrcweir 			SetSizePixel( Size( 600, 450 ) );
96*cdf0e10cSrcweir 			EnablePaint( true );
97*cdf0e10cSrcweir 			Show();
98*cdf0e10cSrcweir 		}
99*cdf0e10cSrcweir 		virtual ~TestWindow() {}
100*cdf0e10cSrcweir         virtual void MouseButtonUp( const MouseEvent& /*rMEvt*/ )
101*cdf0e10cSrcweir 		{
102*cdf0e10cSrcweir 			//TODO: do something cool
103*cdf0e10cSrcweir             EndDialog();
104*cdf0e10cSrcweir         }
105*cdf0e10cSrcweir 		virtual void Paint( const Rectangle& rRect );
106*cdf0e10cSrcweir };
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir class DemoRenderer
109*cdf0e10cSrcweir {
110*cdf0e10cSrcweir 	public:
111*cdf0e10cSrcweir 		Size maSize;
112*cdf0e10cSrcweir 		Size maBox;
113*cdf0e10cSrcweir 		rendering::ViewState   maViewState;
114*cdf0e10cSrcweir 		rendering::RenderState maRenderState;
115*cdf0e10cSrcweir     	uno::Sequence< double > maColorBlack;
116*cdf0e10cSrcweir 		uno::Sequence< double > maColorWhite;
117*cdf0e10cSrcweir 		uno::Sequence< double > maColorRed;
118*cdf0e10cSrcweir 		uno::Reference< rendering::XCanvas > mxCanvas;
119*cdf0e10cSrcweir 		uno::Reference< rendering::XCanvasFont > mxDefaultFont;
120*cdf0e10cSrcweir 		uno::Reference< rendering::XGraphicDevice > mxDevice;
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir 		DemoRenderer( uno::Reference< rendering::XGraphicDevice > xDevice,
123*cdf0e10cSrcweir 					  uno::Reference< rendering::XCanvas > xCanvas,
124*cdf0e10cSrcweir 					  Size aSize ) :
125*cdf0e10cSrcweir             maSize(aSize),
126*cdf0e10cSrcweir             maBox(),
127*cdf0e10cSrcweir             maViewState(),
128*cdf0e10cSrcweir             maRenderState(),
129*cdf0e10cSrcweir             maColorBlack( vcl::unotools::colorToStdColorSpaceSequence( Color(COL_BLACK)) ),
130*cdf0e10cSrcweir             maColorWhite( vcl::unotools::colorToStdColorSpaceSequence( Color(COL_WHITE)) ),
131*cdf0e10cSrcweir             maColorRed( vcl::unotools::colorToStdColorSpaceSequence( Color(COL_RED)) ),
132*cdf0e10cSrcweir             mxCanvas(xCanvas),
133*cdf0e10cSrcweir             mxDefaultFont(),
134*cdf0e10cSrcweir             mxDevice( xDevice )
135*cdf0e10cSrcweir 		{
136*cdf0e10cSrcweir 			// Geometry init
137*cdf0e10cSrcweir 			geometry::AffineMatrix2D aUnit( 1,0, 0,
138*cdf0e10cSrcweir 											0,1, 0 );
139*cdf0e10cSrcweir 			maViewState.AffineTransform = aUnit;
140*cdf0e10cSrcweir 			maRenderState.AffineTransform = aUnit;
141*cdf0e10cSrcweir 			maRenderState.DeviceColor = maColorBlack;
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir 			//I can't figure out what the compsiteoperation stuff does
144*cdf0e10cSrcweir 			//it doesn't seem to do anything in either VCL or cairocanvas
145*cdf0e10cSrcweir 			//I was hoping that CLEAR would clear the canvas before we paint,
146*cdf0e10cSrcweir 			//but nothing changes
147*cdf0e10cSrcweir 			maRenderState.CompositeOperation = rendering::CompositeOperation::OVER;
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir 			maBox.Width() = aSize.Width() / 3;
150*cdf0e10cSrcweir 			maBox.Height() = aSize.Height() / 3;
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir 			lang::Locale aLocale;
153*cdf0e10cSrcweir 			rendering::FontInfo aFontInfo;
154*cdf0e10cSrcweir 			aFontInfo.FamilyName = ::rtl::OUString::createFromAscii( "Swiss" );
155*cdf0e10cSrcweir 			aFontInfo.StyleName = ::rtl::OUString::createFromAscii( "SansSerif" );
156*cdf0e10cSrcweir 			geometry::Matrix2D aFontMatrix( 1, 0,
157*cdf0e10cSrcweir 											0, 1 );
158*cdf0e10cSrcweir 			rendering::FontRequest aFontRequest( aFontInfo, 12.0, 0.0, aLocale );
159*cdf0e10cSrcweir 			uno::Sequence< beans::PropertyValue > aExtraFontProperties;
160*cdf0e10cSrcweir  			mxDefaultFont = xCanvas->createFont( aFontRequest, aExtraFontProperties, aFontMatrix );
161*cdf0e10cSrcweir 			if( !mxDefaultFont.is() )
162*cdf0e10cSrcweir 				fprintf( stderr, "Failed to create font\n" );
163*cdf0e10cSrcweir 		}
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir 		void drawGrid()
166*cdf0e10cSrcweir 		{
167*cdf0e10cSrcweir 			double d, dIncr = maSize.Width() / 3;
168*cdf0e10cSrcweir 			for ( d = 0; d <= maSize.Width(); d += dIncr )
169*cdf0e10cSrcweir 				mxCanvas->drawLine( geometry::RealPoint2D( d, 0 ),
170*cdf0e10cSrcweir 									geometry::RealPoint2D( d, maSize.Height() ),
171*cdf0e10cSrcweir 									maViewState, maRenderState );
172*cdf0e10cSrcweir 			dIncr = maSize.Height() / 3;
173*cdf0e10cSrcweir 			for ( d = 0; d <= maSize.Height(); d += dIncr )
174*cdf0e10cSrcweir 				mxCanvas->drawLine( geometry::RealPoint2D( 0, d ),
175*cdf0e10cSrcweir 									geometry::RealPoint2D( maSize.Width(), d ),
176*cdf0e10cSrcweir 									maViewState, maRenderState );
177*cdf0e10cSrcweir 		}
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir     	void drawStringAt( ::rtl::OString aString, double x, double y )
180*cdf0e10cSrcweir 		{
181*cdf0e10cSrcweir 			rendering::StringContext aText;
182*cdf0e10cSrcweir 			aText.Text = ::rtl::OStringToOUString( aString, RTL_TEXTENCODING_UTF8 );
183*cdf0e10cSrcweir 			aText.StartPosition = 0;
184*cdf0e10cSrcweir 			aText.Length = aString.getLength();
185*cdf0e10cSrcweir 			rendering::RenderState aRenderState( maRenderState );
186*cdf0e10cSrcweir 			aRenderState.AffineTransform.m02 += x;
187*cdf0e10cSrcweir 			aRenderState.AffineTransform.m12 += y;
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir 			mxCanvas->drawText( aText, mxDefaultFont, maViewState, aRenderState, 0);
190*cdf0e10cSrcweir 		}
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir         void drawRect( Rectangle rRect, uno::Sequence< double > &aColor, int /*nWidth*/ )
193*cdf0e10cSrcweir 		{
194*cdf0e10cSrcweir 			uno::Sequence< geometry::RealPoint2D > aPoints(4);
195*cdf0e10cSrcweir 			uno::Reference< rendering::XLinePolyPolygon2D > xPoly;
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir 			aPoints[0] = geometry::RealPoint2D( rRect.Left(),  rRect.Top() );
198*cdf0e10cSrcweir 			aPoints[1] = geometry::RealPoint2D( rRect.Left(),  rRect.Bottom() );
199*cdf0e10cSrcweir 			aPoints[2] = geometry::RealPoint2D( rRect.Right(), rRect.Bottom() );
200*cdf0e10cSrcweir 			aPoints[3] = geometry::RealPoint2D( rRect.Right(), rRect.Top() );
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir 			uno::Sequence< uno::Sequence< geometry::RealPoint2D > > aPolys(1);
203*cdf0e10cSrcweir 			aPolys[0] = aPoints;
204*cdf0e10cSrcweir 			xPoly = mxDevice->createCompatibleLinePolyPolygon( aPolys );
205*cdf0e10cSrcweir 			xPoly->setClosed( 0, true );
206*cdf0e10cSrcweir 			uno::Reference< rendering::XPolyPolygon2D> xPP( xPoly, uno::UNO_QUERY );
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir 			rendering::RenderState aRenderState( maRenderState );
209*cdf0e10cSrcweir 			aRenderState.DeviceColor = aColor;
210*cdf0e10cSrcweir 			mxCanvas->drawPolyPolygon( xPP, maViewState, aRenderState );
211*cdf0e10cSrcweir 		}
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir 		void translate( double x, double y)
214*cdf0e10cSrcweir 		{
215*cdf0e10cSrcweir 			maRenderState.AffineTransform.m02 += x;
216*cdf0e10cSrcweir 			maRenderState.AffineTransform.m12 += y;
217*cdf0e10cSrcweir 		}
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir 		void drawPolishDiamond( double center_x, double center_y)
220*cdf0e10cSrcweir 		{
221*cdf0e10cSrcweir 			const int    VERTICES = 10;
222*cdf0e10cSrcweir 			const double RADIUS = 60.0;
223*cdf0e10cSrcweir 			int i, j;
224*cdf0e10cSrcweir 			double a;
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir 			rendering::RenderState maOldRenderState = maRenderState; // push
227*cdf0e10cSrcweir 			translate( center_x, center_y );
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir 			for (i = 0; i < VERTICES; i++)
230*cdf0e10cSrcweir 			{
231*cdf0e10cSrcweir 				a = 2.0 * M_PI * i / VERTICES;
232*cdf0e10cSrcweir 				geometry::RealPoint2D aSrc( RADIUS * cos (a), RADIUS * sin (a) );
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir 				for (j = i + 1; j < VERTICES; j++)
235*cdf0e10cSrcweir 				{
236*cdf0e10cSrcweir 					a = 2.0 * M_PI * j / VERTICES;
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir //					FIXME: set cap_style to 'ROUND'
239*cdf0e10cSrcweir 					mxCanvas->drawLine( aSrc,
240*cdf0e10cSrcweir 										geometry::RealPoint2D( RADIUS * cos (a),
241*cdf0e10cSrcweir 															   RADIUS * sin (a) ),
242*cdf0e10cSrcweir 										maViewState, maRenderState );
243*cdf0e10cSrcweir 				}
244*cdf0e10cSrcweir 			}
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir 			maRenderState = maOldRenderState; // pop
247*cdf0e10cSrcweir 		}
248*cdf0e10cSrcweir 
249*cdf0e10cSrcweir 		void drawHilbert( double anchor_x, double anchor_y )
250*cdf0e10cSrcweir 		{
251*cdf0e10cSrcweir 			const double SCALE=7.0;
252*cdf0e10cSrcweir 			const char hilbert[] = "urdrrulurulldluuruluurdrurddldrrruluurdrurddldrddlulldrdldrrurd";
253*cdf0e10cSrcweir 			int nLength = sizeof( hilbert ) / sizeof (hilbert [0]);
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir 			uno::Sequence< geometry::RealPoint2D > aPoints( nLength );
256*cdf0e10cSrcweir 			uno::Reference< rendering::XLinePolyPolygon2D > xPoly;
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir 			aPoints[0] = geometry::RealPoint2D( anchor_x, anchor_y );
259*cdf0e10cSrcweir 			for (int i = 0; i < nLength; i++ )
260*cdf0e10cSrcweir 			{
261*cdf0e10cSrcweir 				switch( hilbert[i] )
262*cdf0e10cSrcweir 				{
263*cdf0e10cSrcweir 					case 'u':
264*cdf0e10cSrcweir 						aPoints[i+1] = geometry::RealPoint2D( aPoints[i].X,
265*cdf0e10cSrcweir 															aPoints[i].Y - SCALE );
266*cdf0e10cSrcweir 						break;
267*cdf0e10cSrcweir 					case 'd':
268*cdf0e10cSrcweir 						aPoints[i+1] = geometry::RealPoint2D( aPoints[i].X,
269*cdf0e10cSrcweir 															aPoints[i].Y + SCALE );
270*cdf0e10cSrcweir 						break;
271*cdf0e10cSrcweir 					case 'l':
272*cdf0e10cSrcweir 						aPoints[i+1] = geometry::RealPoint2D( aPoints[i].X - SCALE,
273*cdf0e10cSrcweir 															aPoints[i].Y );
274*cdf0e10cSrcweir 						break;
275*cdf0e10cSrcweir 					case 'r':
276*cdf0e10cSrcweir 						aPoints[i+1] = geometry::RealPoint2D( aPoints[i].X + SCALE,
277*cdf0e10cSrcweir 															aPoints[i].Y );
278*cdf0e10cSrcweir 						break;
279*cdf0e10cSrcweir 				}
280*cdf0e10cSrcweir 			}
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir 			uno::Sequence< uno::Sequence< geometry::RealPoint2D > > aPolys(1);
283*cdf0e10cSrcweir 			aPolys[0] = aPoints;
284*cdf0e10cSrcweir 
285*cdf0e10cSrcweir 			xPoly = mxDevice->createCompatibleLinePolyPolygon( aPolys );
286*cdf0e10cSrcweir 			xPoly->setClosed( 0, false );
287*cdf0e10cSrcweir 			uno::Reference< rendering::XPolyPolygon2D> xPP( xPoly, uno::UNO_QUERY );
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir 			rendering::RenderState aRenderState( maRenderState );
290*cdf0e10cSrcweir 			aRenderState.DeviceColor = maColorRed;
291*cdf0e10cSrcweir //			aRenderState.DeviceColor[3] = 0.5;
292*cdf0e10cSrcweir 			rendering::StrokeAttributes aStrokeAttrs;
293*cdf0e10cSrcweir 			aStrokeAttrs.StrokeWidth = 4.0;
294*cdf0e10cSrcweir 			aStrokeAttrs.MiterLimit = 2.0; // ?
295*cdf0e10cSrcweir 			aStrokeAttrs.StartCapType = rendering::PathCapType::BUTT;
296*cdf0e10cSrcweir 			aStrokeAttrs.EndCapType = rendering::PathCapType::BUTT;
297*cdf0e10cSrcweir 			aStrokeAttrs.JoinType = rendering::PathJoinType::MITER;
298*cdf0e10cSrcweir 			//fprintf( stderr, "FIXME: stroking a PolyPolygon doesn't show up\n" );
299*cdf0e10cSrcweir 			//yes it does
300*cdf0e10cSrcweir 			mxCanvas->strokePolyPolygon( xPP, maViewState, aRenderState, aStrokeAttrs );
301*cdf0e10cSrcweir 			// FIXME: do this instead:
302*cdf0e10cSrcweir 			//mxCanvas->drawPolyPolygon( xPP, maViewState, aRenderState );
303*cdf0e10cSrcweir 		}
304*cdf0e10cSrcweir 
305*cdf0e10cSrcweir 		void drawTitle( rtl::OString aTitle )
306*cdf0e10cSrcweir 		{
307*cdf0e10cSrcweir 			// FIXME: text anchoring to be done
308*cdf0e10cSrcweir 			double nStringWidth = aTitle.getLength() * 8.0;
309*cdf0e10cSrcweir 			drawStringAt ( aTitle, (maBox.Width() - nStringWidth) / 2, 15 );
310*cdf0e10cSrcweir 		}
311*cdf0e10cSrcweir 
312*cdf0e10cSrcweir 		void drawRectangles()
313*cdf0e10cSrcweir 		{
314*cdf0e10cSrcweir 			rendering::RenderState maOldRenderState = maRenderState; // push
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir 			drawTitle( ::rtl::OString( "Rectangles" ) );
317*cdf0e10cSrcweir 
318*cdf0e10cSrcweir 			drawRect( Rectangle( 20, 30, 70, 60 ), maColorRed, 8 );
319*cdf0e10cSrcweir 			// color mediumseagreen, stipple fill, outline black
320*cdf0e10cSrcweir 			drawRect( Rectangle( 90, 40, 180, 100 ), maColorBlack, 4 );
321*cdf0e10cSrcweir 			// color steelblue, filled, no outline
322*cdf0e10cSrcweir 			drawRect( Rectangle( 10, 80, 80, 140 ), maColorBlack, 1 );
323*cdf0e10cSrcweir 
324*cdf0e10cSrcweir 			maRenderState = maOldRenderState; // pop
325*cdf0e10cSrcweir 		}
326*cdf0e10cSrcweir 
327*cdf0e10cSrcweir 		void drawEllipses()
328*cdf0e10cSrcweir 		{
329*cdf0e10cSrcweir 			rendering::RenderState maOldRenderState = maRenderState; // push
330*cdf0e10cSrcweir 			translate( maBox.Width(), 0.0 );
331*cdf0e10cSrcweir 
332*cdf0e10cSrcweir 			drawTitle( ::rtl::OString( "Ellipses" ) );
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir             const basegfx::B2DPoint aCenter( maBox.Width()*.5,
335*cdf0e10cSrcweir                                              maBox.Height()*.5 );
336*cdf0e10cSrcweir             const basegfx::B2DPoint aRadii( maBox.Width()*.3,
337*cdf0e10cSrcweir                                             maBox.Height()*.3 );
338*cdf0e10cSrcweir             const basegfx::B2DPolygon& rEllipse(
339*cdf0e10cSrcweir                 basegfx::tools::createPolygonFromEllipse( aCenter,
340*cdf0e10cSrcweir                                                           aRadii.getX(),
341*cdf0e10cSrcweir                                                           aRadii.getY() ));
342*cdf0e10cSrcweir 
343*cdf0e10cSrcweir 			uno::Reference< rendering::XPolyPolygon2D > xPoly(
344*cdf0e10cSrcweir                 basegfx::unotools::xPolyPolygonFromB2DPolygon(mxDevice,
345*cdf0e10cSrcweir                                                               rEllipse) );
346*cdf0e10cSrcweir 
347*cdf0e10cSrcweir 			rendering::StrokeAttributes aStrokeAttrs;
348*cdf0e10cSrcweir 			aStrokeAttrs.StrokeWidth = 4.0;
349*cdf0e10cSrcweir 			aStrokeAttrs.MiterLimit = 2.0; // ?
350*cdf0e10cSrcweir 			aStrokeAttrs.StartCapType = rendering::PathCapType::BUTT;
351*cdf0e10cSrcweir 			aStrokeAttrs.EndCapType = rendering::PathCapType::BUTT;
352*cdf0e10cSrcweir 			aStrokeAttrs.JoinType = rendering::PathJoinType::MITER;
353*cdf0e10cSrcweir 			mxCanvas->strokePolyPolygon( xPoly, maViewState, maRenderState, aStrokeAttrs );
354*cdf0e10cSrcweir 
355*cdf0e10cSrcweir 			maRenderState = maOldRenderState; // pop
356*cdf0e10cSrcweir 		}
357*cdf0e10cSrcweir 
358*cdf0e10cSrcweir 		void drawText()
359*cdf0e10cSrcweir 		{
360*cdf0e10cSrcweir 			rendering::RenderState maOldRenderState = maRenderState; // push
361*cdf0e10cSrcweir 			translate( maBox.Width() * 2.0, 0.0 );
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir 			drawTitle( ::rtl::OString( "Text" ) );
364*cdf0e10cSrcweir 
365*cdf0e10cSrcweir 			translate( 0.0,
366*cdf0e10cSrcweir                        maBox.Height() * .5 );
367*cdf0e10cSrcweir 			drawTitle( ::rtl::OString( "This is lame" ) );
368*cdf0e10cSrcweir 
369*cdf0e10cSrcweir 			maRenderState = maOldRenderState; // pop
370*cdf0e10cSrcweir 		}
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir 		void drawImages()
373*cdf0e10cSrcweir 		{
374*cdf0e10cSrcweir 			rendering::RenderState maOldRenderState = maRenderState; // push
375*cdf0e10cSrcweir 			translate( 0.0, maBox.Height() );
376*cdf0e10cSrcweir 
377*cdf0e10cSrcweir 			drawTitle( ::rtl::OString( "Images" ) );
378*cdf0e10cSrcweir 
379*cdf0e10cSrcweir 			uno::Reference< rendering::XBitmap > xBitmap(mxCanvas, uno::UNO_QUERY);
380*cdf0e10cSrcweir 
381*cdf0e10cSrcweir             if( !xBitmap.is() )
382*cdf0e10cSrcweir                 return;
383*cdf0e10cSrcweir 
384*cdf0e10cSrcweir 			translate( maBox.Width()*0.1, maBox.Height()*0.2 );
385*cdf0e10cSrcweir 			maRenderState.AffineTransform.m00 *= 4.0/15;
386*cdf0e10cSrcweir 			maRenderState.AffineTransform.m11 *= 3.0/15;
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir 			mxCanvas->drawBitmap(xBitmap, maViewState, maRenderState);
389*cdf0e10cSrcweir 
390*cdf0e10cSrcweir 			// uno::Reference< rendering::XBitmap > xBitmap2( xBitmap->getScaledBitmap(geometry::RealSize2D(48, 48), false) );
391*cdf0e10cSrcweir 			// mxCanvas->drawBitmap(xBitmap2, maViewState, maRenderState); //yes, but where?
392*cdf0e10cSrcweir 			//cairo-canvas says:
393*cdf0e10cSrcweir 			//called CanvasHelper::getScaledBitmap, we return NULL, TODO
394*cdf0e10cSrcweir             //Exception 'BitmapEx vclcanvas::tools::bitmapExFromXBitmap(const com::sun::star::uno::Reference<com::sun::star::rendering::XBitmap>&),
395*cdf0e10cSrcweir             //bitmapExFromXBitmap(): could not extract BitmapEx' thrown
396*cdf0e10cSrcweir 			//
397*cdf0e10cSrcweir             //vcl-canvas says:
398*cdf0e10cSrcweir 			//Exception 'BitmapEx vclcanvas::tools::bitmapExFromXBitmap(const com::sun::star::uno::Reference<com::sun::star::rendering::XBitmap>&),
399*cdf0e10cSrcweir 			//bitmapExFromXBitmap(): could not extract bitmap' thrown
400*cdf0e10cSrcweir 			//  Thorsten says that this is a bug, and Thorsten never lies.
401*cdf0e10cSrcweir 
402*cdf0e10cSrcweir 			maRenderState = maOldRenderState; // pop
403*cdf0e10cSrcweir 		}
404*cdf0e10cSrcweir 
405*cdf0e10cSrcweir 		void drawLines()
406*cdf0e10cSrcweir 		{
407*cdf0e10cSrcweir 			rendering::RenderState maOldRenderState = maRenderState; // push
408*cdf0e10cSrcweir 			translate( maBox.Width(), maBox.Height() );
409*cdf0e10cSrcweir 
410*cdf0e10cSrcweir 			drawTitle( ::rtl::OString( "Lines" ) );
411*cdf0e10cSrcweir 
412*cdf0e10cSrcweir 			drawPolishDiamond( 70.0, 80.0 );
413*cdf0e10cSrcweir 			drawHilbert( 140.0, 140.0 );
414*cdf0e10cSrcweir 
415*cdf0e10cSrcweir 			maRenderState = maOldRenderState; // pop
416*cdf0e10cSrcweir 		}
417*cdf0e10cSrcweir 
418*cdf0e10cSrcweir 		void drawCurves()
419*cdf0e10cSrcweir 		{
420*cdf0e10cSrcweir 			rendering::RenderState maOldRenderState = maRenderState; // push
421*cdf0e10cSrcweir 			translate( maBox.Width() * 2.0, maBox.Height() );
422*cdf0e10cSrcweir 
423*cdf0e10cSrcweir 			drawTitle( ::rtl::OString( "Curves" ) );
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir 			translate( maBox.Width() * .5, maBox.Height() * .5 );
426*cdf0e10cSrcweir 
427*cdf0e10cSrcweir 			const double r= 30.0;
428*cdf0e10cSrcweir 			const int num_curves = 3;
429*cdf0e10cSrcweir 
430*cdf0e10cSrcweir 			//hacky hack hack
431*cdf0e10cSrcweir 			uno::Sequence< geometry::RealBezierSegment2D > aBeziers (num_curves);
432*cdf0e10cSrcweir 			uno::Reference< rendering::XBezierPolyPolygon2D > xPoly;
433*cdf0e10cSrcweir 
434*cdf0e10cSrcweir 			for (int i= 0; i < num_curves; i++)
435*cdf0e10cSrcweir 				aBeziers[i]= geometry::RealBezierSegment2D( r * cos(i*2*M_PI/num_curves), //Px
436*cdf0e10cSrcweir 															r * sin(i*2*M_PI/num_curves), //py
437*cdf0e10cSrcweir 															r * 2 * cos((i*2*M_PI + 2*M_PI)/num_curves),  //C1x
438*cdf0e10cSrcweir 															r * 2 * sin((i*2*M_PI + 2*M_PI)/num_curves),  //C1y
439*cdf0e10cSrcweir 															r * 2 * cos((i*2*M_PI + 2*M_PI)/num_curves),  //C2x
440*cdf0e10cSrcweir 															r * 2 * sin((i*2*M_PI + 2*M_PI)/num_curves)); //C2y
441*cdf0e10cSrcweir 			uno::Sequence< uno::Sequence< geometry::RealBezierSegment2D > > aPolys(1);
442*cdf0e10cSrcweir 			aPolys[0] = aBeziers;
443*cdf0e10cSrcweir 			xPoly = mxDevice->createCompatibleBezierPolyPolygon(aPolys);
444*cdf0e10cSrcweir 			xPoly->setClosed( 0, true );
445*cdf0e10cSrcweir 			//uno::Reference< rendering::XBezierPolyPolygon2D> xPP( xPoly, uno::UNO_QUERY );
446*cdf0e10cSrcweir 			//compiles, but totally screws up.  I think it is interpretting the bezier as a line
447*cdf0e10cSrcweir 			uno::Reference< rendering::XPolyPolygon2D> xPP( xPoly, uno::UNO_QUERY );
448*cdf0e10cSrcweir 
449*cdf0e10cSrcweir 			rendering::StrokeAttributes aStrokeAttrs;
450*cdf0e10cSrcweir 			aStrokeAttrs.StrokeWidth = 4.0;
451*cdf0e10cSrcweir 			aStrokeAttrs.MiterLimit = 2.0; // ?
452*cdf0e10cSrcweir 			aStrokeAttrs.StartCapType = rendering::PathCapType::BUTT;
453*cdf0e10cSrcweir 			aStrokeAttrs.EndCapType = rendering::PathCapType::BUTT;
454*cdf0e10cSrcweir 			aStrokeAttrs.JoinType = rendering::PathJoinType::MITER;
455*cdf0e10cSrcweir 			mxCanvas->strokePolyPolygon( xPP, maViewState, maRenderState, aStrokeAttrs );
456*cdf0e10cSrcweir 			//you can't draw a BezierPolyPolygon2D with this, even though it is derived from it
457*cdf0e10cSrcweir 			//mxCanvas->drawPolyPolygon( xPP, maViewState, maRenderState );
458*cdf0e10cSrcweir 
459*cdf0e10cSrcweir 			maRenderState = maOldRenderState; // pop
460*cdf0e10cSrcweir 		}
461*cdf0e10cSrcweir 
462*cdf0e10cSrcweir 	double gimmerand()
463*cdf0e10cSrcweir 		{
464*cdf0e10cSrcweir 			return (double)(rand()) / RAND_MAX * 100 + 50;
465*cdf0e10cSrcweir 		}
466*cdf0e10cSrcweir 
467*cdf0e10cSrcweir 		void drawArcs()
468*cdf0e10cSrcweir 		{
469*cdf0e10cSrcweir 			rendering::RenderState maOldRenderState = maRenderState; // push
470*cdf0e10cSrcweir 			translate( 0.0, maBox.Height() * 2.0 );
471*cdf0e10cSrcweir 
472*cdf0e10cSrcweir 			drawTitle( ::rtl::OString( "Arcs" ) );
473*cdf0e10cSrcweir 
474*cdf0e10cSrcweir 
475*cdf0e10cSrcweir 			//begin hacks
476*cdf0e10cSrcweir 			//This stuff doesn't belong here, but probably in curves
477*cdf0e10cSrcweir 			//This stuff doesn't work in VCL b/c vcl doesn't do beziers
478*cdf0e10cSrcweir 			//Hah!  Everytime the window redraws, we do this
479*cdf0e10cSrcweir 			double ax;
480*cdf0e10cSrcweir 			double ay;
481*cdf0e10cSrcweir 			double bx;
482*cdf0e10cSrcweir 			double by;
483*cdf0e10cSrcweir 			bx= gimmerand();
484*cdf0e10cSrcweir 			by= gimmerand();
485*cdf0e10cSrcweir 
486*cdf0e10cSrcweir 			for (int i= 0; i < 1; i++)
487*cdf0e10cSrcweir 			{
488*cdf0e10cSrcweir 				//point a= point b;
489*cdf0e10cSrcweir 				ax= bx;
490*cdf0e10cSrcweir 				ay= by;
491*cdf0e10cSrcweir 				//point b= rand;
492*cdf0e10cSrcweir 				bx= gimmerand();
493*cdf0e10cSrcweir 				by= gimmerand();
494*cdf0e10cSrcweir 				double c1x= gimmerand();
495*cdf0e10cSrcweir 				double c1y= gimmerand();
496*cdf0e10cSrcweir 				double c2x= gimmerand();
497*cdf0e10cSrcweir 				double c2y= gimmerand();
498*cdf0e10cSrcweir 				maRenderState.DeviceColor = maColorRed;
499*cdf0e10cSrcweir 				mxCanvas->drawLine(geometry::RealPoint2D(ax, ay), geometry::RealPoint2D(c1x, c1y), maViewState, maRenderState);
500*cdf0e10cSrcweir 				mxCanvas->drawLine(geometry::RealPoint2D(c1x, c1y), geometry::RealPoint2D(c2x, c2y), maViewState, maRenderState);
501*cdf0e10cSrcweir 				mxCanvas->drawLine(geometry::RealPoint2D(bx, by), geometry::RealPoint2D(c2x, c2y), maViewState, maRenderState);
502*cdf0e10cSrcweir  				//draw from a to b
503*cdf0e10cSrcweir 				geometry::RealBezierSegment2D aBezierSegment(
504*cdf0e10cSrcweir 					ax, //Px
505*cdf0e10cSrcweir 					ay, //Py
506*cdf0e10cSrcweir 					c1x,
507*cdf0e10cSrcweir 					c1x,
508*cdf0e10cSrcweir 					c2x,
509*cdf0e10cSrcweir 					c2y
510*cdf0e10cSrcweir 					);
511*cdf0e10cSrcweir 				geometry::RealPoint2D aEndPoint(bx, by);
512*cdf0e10cSrcweir 				maRenderState.DeviceColor = maColorBlack;
513*cdf0e10cSrcweir 				mxCanvas->drawBezier(
514*cdf0e10cSrcweir 					aBezierSegment,
515*cdf0e10cSrcweir 					aEndPoint,
516*cdf0e10cSrcweir 					maViewState, maRenderState );
517*cdf0e10cSrcweir 			}
518*cdf0e10cSrcweir 			maRenderState = maOldRenderState; // pop
519*cdf0e10cSrcweir 		}
520*cdf0e10cSrcweir 
521*cdf0e10cSrcweir 
522*cdf0e10cSrcweir 	void drawRegularPolygon(double centerx, double centery, int sides, double r)
523*cdf0e10cSrcweir 		{
524*cdf0e10cSrcweir 			//hacky hack hack
525*cdf0e10cSrcweir 			uno::Sequence< geometry::RealPoint2D > aPoints (sides);
526*cdf0e10cSrcweir 			uno::Reference< rendering::XLinePolyPolygon2D > xPoly;
527*cdf0e10cSrcweir 
528*cdf0e10cSrcweir 			for (int i= 0; i < sides; i++)
529*cdf0e10cSrcweir 			{
530*cdf0e10cSrcweir 				aPoints[i]= geometry::RealPoint2D( centerx + r * cos(i*2 * M_PI/sides),
531*cdf0e10cSrcweir 												   centery + r * sin(i*2 * M_PI/sides));
532*cdf0e10cSrcweir 			}
533*cdf0e10cSrcweir 			uno::Sequence< uno::Sequence< geometry::RealPoint2D > > aPolys(1);
534*cdf0e10cSrcweir 			aPolys[0] = aPoints;
535*cdf0e10cSrcweir 			xPoly = mxDevice->createCompatibleLinePolyPolygon( aPolys );
536*cdf0e10cSrcweir 			xPoly->setClosed( 0, true );
537*cdf0e10cSrcweir 			rendering::RenderState aRenderState( maRenderState );
538*cdf0e10cSrcweir 			aRenderState.DeviceColor = maColorRed;
539*cdf0e10cSrcweir 			uno::Reference< rendering::XPolyPolygon2D> xPP( xPoly, uno::UNO_QUERY );
540*cdf0e10cSrcweir 			mxCanvas->drawPolyPolygon( xPP, maViewState, aRenderState);
541*cdf0e10cSrcweir 			mxCanvas->fillPolyPolygon( xPP,
542*cdf0e10cSrcweir 									   maViewState,
543*cdf0e10cSrcweir 									   aRenderState );
544*cdf0e10cSrcweir 		}
545*cdf0e10cSrcweir 
546*cdf0e10cSrcweir 		void drawPolygons()
547*cdf0e10cSrcweir 		{
548*cdf0e10cSrcweir 			rendering::RenderState maOldRenderState = maRenderState; // push
549*cdf0e10cSrcweir 			translate( maBox.Width() * 1.0, maBox.Height() * 2.0 );
550*cdf0e10cSrcweir 
551*cdf0e10cSrcweir 			drawTitle( ::rtl::OString( "Polgyons" ) );
552*cdf0e10cSrcweir 
553*cdf0e10cSrcweir 			int sides= 3;
554*cdf0e10cSrcweir 			for (int i= 1; i <= 4; i++)
555*cdf0e10cSrcweir 			{
556*cdf0e10cSrcweir 				drawRegularPolygon(35*i, 35, sides, 15);
557*cdf0e10cSrcweir 				sides++;
558*cdf0e10cSrcweir 			}
559*cdf0e10cSrcweir 
560*cdf0e10cSrcweir 			maRenderState = maOldRenderState; // pop
561*cdf0e10cSrcweir 		}
562*cdf0e10cSrcweir 
563*cdf0e10cSrcweir 		void drawWidgets() // FIXME: prolly makes no sense
564*cdf0e10cSrcweir 		{
565*cdf0e10cSrcweir 			rendering::RenderState maOldRenderState = maRenderState; // push
566*cdf0e10cSrcweir 			translate( maBox.Width() * 2.0, maBox.Height() * 2.0 );
567*cdf0e10cSrcweir 
568*cdf0e10cSrcweir 			drawTitle( ::rtl::OString( "Widgets" ) );
569*cdf0e10cSrcweir 
570*cdf0e10cSrcweir 			maRenderState = maOldRenderState; // pop
571*cdf0e10cSrcweir 		}
572*cdf0e10cSrcweir };
573*cdf0e10cSrcweir 
574*cdf0e10cSrcweir 
575*cdf0e10cSrcweir void TestWindow::Paint( const Rectangle& /*rRect*/ )
576*cdf0e10cSrcweir {
577*cdf0e10cSrcweir 	try
578*cdf0e10cSrcweir 	{
579*cdf0e10cSrcweir         const Size aVDevSize(300,300);
580*cdf0e10cSrcweir         VirtualDevice aVDev(*this);
581*cdf0e10cSrcweir         aVDev.SetOutputSizePixel(aVDevSize);
582*cdf0e10cSrcweir 		uno::Reference< rendering::XCanvas > xVDevCanvas( aVDev.GetCanvas(),
583*cdf0e10cSrcweir                                                           uno::UNO_QUERY_THROW );
584*cdf0e10cSrcweir 		uno::Reference< rendering::XGraphicDevice > xVDevDevice( xVDevCanvas->getDevice(),
585*cdf0e10cSrcweir                                                                  uno::UNO_QUERY_THROW );
586*cdf0e10cSrcweir 		DemoRenderer aVDevRenderer( xVDevDevice, xVDevCanvas, aVDevSize);
587*cdf0e10cSrcweir         xVDevCanvas->clear();
588*cdf0e10cSrcweir 		aVDevRenderer.drawGrid();
589*cdf0e10cSrcweir         aVDevRenderer.drawRectangles();
590*cdf0e10cSrcweir 		aVDevRenderer.drawEllipses();
591*cdf0e10cSrcweir 		aVDevRenderer.drawText();
592*cdf0e10cSrcweir         aVDevRenderer.drawLines();
593*cdf0e10cSrcweir         aVDevRenderer.drawCurves();
594*cdf0e10cSrcweir         aVDevRenderer.drawArcs();
595*cdf0e10cSrcweir         aVDevRenderer.drawPolygons();
596*cdf0e10cSrcweir 
597*cdf0e10cSrcweir 		uno::Reference< rendering::XCanvas > xCanvas( GetSpriteCanvas(),
598*cdf0e10cSrcweir 	                                                      uno::UNO_QUERY_THROW );
599*cdf0e10cSrcweir 		uno::Reference< rendering::XGraphicDevice > xDevice( xCanvas->getDevice(),
600*cdf0e10cSrcweir                                                              uno::UNO_QUERY_THROW );
601*cdf0e10cSrcweir 
602*cdf0e10cSrcweir 		DemoRenderer aRenderer( xDevice, xCanvas, GetSizePixel() );
603*cdf0e10cSrcweir         xCanvas->clear();
604*cdf0e10cSrcweir 		aRenderer.drawGrid();
605*cdf0e10cSrcweir         aRenderer.drawRectangles();
606*cdf0e10cSrcweir 		aRenderer.drawEllipses();
607*cdf0e10cSrcweir 		aRenderer.drawText();
608*cdf0e10cSrcweir         aRenderer.drawLines();
609*cdf0e10cSrcweir         aRenderer.drawCurves();
610*cdf0e10cSrcweir         aRenderer.drawArcs();
611*cdf0e10cSrcweir         aRenderer.drawPolygons();
612*cdf0e10cSrcweir         aRenderer.drawWidgets();
613*cdf0e10cSrcweir 		aRenderer.drawImages();
614*cdf0e10cSrcweir 
615*cdf0e10cSrcweir         // check whether virdev actually contained something
616*cdf0e10cSrcweir         uno::Reference< rendering::XBitmap > xBitmap(xVDevCanvas, uno::UNO_QUERY);
617*cdf0e10cSrcweir         if( !xBitmap.is() )
618*cdf0e10cSrcweir             return;
619*cdf0e10cSrcweir 
620*cdf0e10cSrcweir         aRenderer.maRenderState.AffineTransform.m02 += 100;
621*cdf0e10cSrcweir         aRenderer.maRenderState.AffineTransform.m12 += 100;
622*cdf0e10cSrcweir         xCanvas->drawBitmap(xBitmap, aRenderer.maViewState, aRenderer.maRenderState);
623*cdf0e10cSrcweir 
624*cdf0e10cSrcweir 		uno::Reference< rendering::XSpriteCanvas > xSpriteCanvas( xCanvas,
625*cdf0e10cSrcweir                                                                   uno::UNO_QUERY );
626*cdf0e10cSrcweir         if( xSpriteCanvas.is() )
627*cdf0e10cSrcweir             xSpriteCanvas->updateScreen( sal_True ); // without
628*cdf0e10cSrcweir                                                      // updateScreen(),
629*cdf0e10cSrcweir                                                      // nothing is
630*cdf0e10cSrcweir                                                      // visible
631*cdf0e10cSrcweir 	}
632*cdf0e10cSrcweir 	catch (const uno::Exception &e)
633*cdf0e10cSrcweir 	{
634*cdf0e10cSrcweir 		fprintf( stderr, "Exception '%s' thrown\n" ,
635*cdf0e10cSrcweir 				 (const sal_Char *) ::rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ) );
636*cdf0e10cSrcweir 	}
637*cdf0e10cSrcweir }
638*cdf0e10cSrcweir 
639*cdf0e10cSrcweir USHORT DemoApp::Exception( USHORT nError )
640*cdf0e10cSrcweir {
641*cdf0e10cSrcweir 	switch( nError & EXC_MAJORTYPE )
642*cdf0e10cSrcweir 	{
643*cdf0e10cSrcweir 		case EXC_RSCNOTLOADED:
644*cdf0e10cSrcweir 			Abort( String::CreateFromAscii( "Error: could not load language resources.\nPlease check your installation.\n" ) );
645*cdf0e10cSrcweir 			break;
646*cdf0e10cSrcweir 	}
647*cdf0e10cSrcweir 	return 0;
648*cdf0e10cSrcweir }
649*cdf0e10cSrcweir 
650*cdf0e10cSrcweir void DemoApp::Main()
651*cdf0e10cSrcweir {
652*cdf0e10cSrcweir 	bool bHelp = false;
653*cdf0e10cSrcweir 
654*cdf0e10cSrcweir 	for( USHORT i = 0; i < GetCommandLineParamCount(); i++ )
655*cdf0e10cSrcweir 	{
656*cdf0e10cSrcweir 		::rtl::OUString aParam = GetCommandLineParam( i );
657*cdf0e10cSrcweir 
658*cdf0e10cSrcweir 		if( aParam.equalsAscii( "--help" ) ||
659*cdf0e10cSrcweir 			aParam.equalsAscii( "-h" ) )
660*cdf0e10cSrcweir 				bHelp = true;
661*cdf0e10cSrcweir 	}
662*cdf0e10cSrcweir 
663*cdf0e10cSrcweir 	if( bHelp )
664*cdf0e10cSrcweir 	{
665*cdf0e10cSrcweir 		PrintHelp();
666*cdf0e10cSrcweir 		return;
667*cdf0e10cSrcweir 	}
668*cdf0e10cSrcweir 
669*cdf0e10cSrcweir 	//-------------------------------------------------
670*cdf0e10cSrcweir 	// create the global service-manager
671*cdf0e10cSrcweir 	//-------------------------------------------------
672*cdf0e10cSrcweir     uno::Reference< lang::XMultiServiceFactory > xFactory;
673*cdf0e10cSrcweir     try
674*cdf0e10cSrcweir     {
675*cdf0e10cSrcweir         uno::Reference< uno::XComponentContext > xCtx = ::cppu::defaultBootstrap_InitialComponentContext();
676*cdf0e10cSrcweir         xFactory = uno::Reference< lang::XMultiServiceFactory >(  xCtx->getServiceManager(),
677*cdf0e10cSrcweir                                                                   uno::UNO_QUERY );
678*cdf0e10cSrcweir         if( xFactory.is() )
679*cdf0e10cSrcweir             ::comphelper::setProcessServiceFactory( xFactory );
680*cdf0e10cSrcweir     }
681*cdf0e10cSrcweir     catch( uno::Exception& )
682*cdf0e10cSrcweir     {
683*cdf0e10cSrcweir     }
684*cdf0e10cSrcweir 
685*cdf0e10cSrcweir     if( !xFactory.is() )
686*cdf0e10cSrcweir     {
687*cdf0e10cSrcweir         fprintf( stderr, "Could not bootstrap UNO, installation must be in disorder. Exiting.\n" );
688*cdf0e10cSrcweir         exit( 1 );
689*cdf0e10cSrcweir     }
690*cdf0e10cSrcweir 
691*cdf0e10cSrcweir     // Create UCB.
692*cdf0e10cSrcweir     uno::Sequence< uno::Any > aArgs( 2 );
693*cdf0e10cSrcweir 	aArgs[ 0 ] <<= rtl::OUString::createFromAscii( UCB_CONFIGURATION_KEY1_LOCAL );
694*cdf0e10cSrcweir 	aArgs[ 1 ] <<= rtl::OUString::createFromAscii( UCB_CONFIGURATION_KEY2_OFFICE );
695*cdf0e10cSrcweir     ::ucbhelper::ContentBroker::initialize( xFactory, aArgs );
696*cdf0e10cSrcweir 
697*cdf0e10cSrcweir 	InitVCL( xFactory );
698*cdf0e10cSrcweir 	TestWindow pWindow;
699*cdf0e10cSrcweir 	pWindow.Execute();
700*cdf0e10cSrcweir     DeInitVCL();
701*cdf0e10cSrcweir 
702*cdf0e10cSrcweir     // clean up UCB
703*cdf0e10cSrcweir 	::ucbhelper::ContentBroker::deinitialize();
704*cdf0e10cSrcweir }
705*cdf0e10cSrcweir 
706*cdf0e10cSrcweir DemoApp aDemoApp;
707*cdf0e10cSrcweir 
708*cdf0e10cSrcweir // TODO
709*cdf0e10cSrcweir //   - bouncing clip-rectangle mode - bounce a clip-rect around the window ...
710*cdf0e10cSrcweir //   - complete all of pre-existing canvas bits
711*cdf0e10cSrcweir //   - affine transform tweakage ...
712*cdf0e10cSrcweir 
713