merge the formfield patch from ooo-build
[ooovba.git] / vcl / workben / svptest.cxx
blob32602d96057ccc2e363cb95e2b63cba887ec2642
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: svptest.cxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <sal/main.h>
32 #include <tools/extendapplicationenvironment.hxx>
33 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
35 #include <vcl/event.hxx>
36 #include <vcl/svapp.hxx>
37 #include <vcl/wrkwin.hxx>
38 #include <vcl/gradient.hxx>
39 #include <vcl/lineinfo.hxx>
40 #include <vcl/bitmap.hxx>
41 #include <vcl/bmpacc.hxx>
42 #include <vcl/metric.hxx>
44 #include <rtl/ustrbuf.hxx>
46 #include <math.h>
48 #include <comphelper/processfactory.hxx>
49 #include <cppuhelper/servicefactory.hxx>
50 #include <cppuhelper/bootstrap.hxx>
52 using namespace rtl;
53 using namespace ::com::sun::star::uno;
54 using namespace ::com::sun::star::lang;
55 // -----------------------------------------------------------------------
57 // Forward declaration
58 void Main();
60 // -----------------------------------------------------------------------
62 SAL_IMPLEMENT_MAIN()
64 tools::extendApplicationEnvironment();
66 Reference< XMultiServiceFactory > xMS;
67 xMS = cppu::createRegistryServiceFactory( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "applicat.rdb" ) ), sal_True );
69 InitVCL( xMS );
70 ::Main();
71 DeInitVCL();
73 return 0;
76 // -----------------------------------------------------------------------
78 class MyWin : public WorkWindow
80 Bitmap m_aBitmap;
81 public:
82 MyWin( Window* pParent, WinBits nWinStyle );
84 void MouseMove( const MouseEvent& rMEvt );
85 void MouseButtonDown( const MouseEvent& rMEvt );
86 void MouseButtonUp( const MouseEvent& rMEvt );
87 void KeyInput( const KeyEvent& rKEvt );
88 void KeyUp( const KeyEvent& rKEvt );
89 void Paint( const Rectangle& rRect );
90 void Resize();
93 // -----------------------------------------------------------------------
95 void Main()
97 MyWin aMainWin( NULL, WB_APP | WB_STDWORK );
98 aMainWin.SetText( XubString( RTL_CONSTASCII_USTRINGPARAM( "VCL - Workbench" ) ) );
99 aMainWin.Show();
101 Application::Execute();
104 // -----------------------------------------------------------------------
106 MyWin::MyWin( Window* pParent, WinBits nWinStyle ) :
107 WorkWindow( pParent, nWinStyle ),
108 m_aBitmap( Size( 256, 256 ), 32 )
110 // prepare an alpha mask
111 BitmapWriteAccess* pAcc = m_aBitmap.AcquireWriteAccess();
112 for( int nX = 0; nX < 256; nX++ )
114 for( int nY = 0; nY < 256; nY++ )
116 double fRed = 255.0-1.5*sqrt((double)(nX*nX+nY*nY));
117 if( fRed < 0.0 )
118 fRed = 0.0;
119 double fGreen = 255.0-1.5*sqrt((double)(((255-nX)*(255-nX)+nY*nY)));
120 if( fGreen < 0.0 )
121 fGreen = 0.0;
122 double fBlue = 255.0-1.5*sqrt((double)((128-nX)*(128-nX)+(255-nY)*(255-nY)));
123 if( fBlue < 0.0 )
124 fBlue = 0.0;
125 pAcc->SetPixel( nX, nY, BitmapColor( sal_uInt8(fRed), sal_uInt8(fGreen), sal_uInt8(fBlue) ) );
128 m_aBitmap.ReleaseAccess( pAcc );
131 // -----------------------------------------------------------------------
133 void MyWin::MouseMove( const MouseEvent& rMEvt )
135 WorkWindow::MouseMove( rMEvt );
138 // -----------------------------------------------------------------------
140 void MyWin::MouseButtonDown( const MouseEvent& rMEvt )
142 WorkWindow::MouseButtonDown( rMEvt );
145 // -----------------------------------------------------------------------
147 void MyWin::MouseButtonUp( const MouseEvent& rMEvt )
149 WorkWindow::MouseButtonUp( rMEvt );
152 // -----------------------------------------------------------------------
154 void MyWin::KeyInput( const KeyEvent& rKEvt )
156 WorkWindow::KeyInput( rKEvt );
159 // -----------------------------------------------------------------------
161 void MyWin::KeyUp( const KeyEvent& rKEvt )
163 WorkWindow::KeyUp( rKEvt );
166 // -----------------------------------------------------------------------
168 static Point project( const Point& rPoint )
170 const double angle_x = M_PI / 6.0;
171 const double angle_z = M_PI / 6.0;
173 // transform planar coordinates to 3d
174 double x = rPoint.X();
175 double y = rPoint.Y();
176 //double z = 0;
178 // rotate around X axis
179 double x1 = x;
180 double y1 = y * cos( angle_x );
181 double z1 = y * sin( angle_x );
183 // rotate around Z axis
184 double x2 = x1 * cos( angle_z ) + y1 * sin( angle_z );
185 //double y2 = y1 * cos( angle_z ) - x1 * sin( angle_z );
186 double z2 = z1;
188 return Point( (sal_Int32)x2, (sal_Int32)z2 );
191 static Color approachColor( const Color& rFrom, const Color& rTo )
193 Color aColor;
194 UINT8 nDiff;
195 // approach red
196 if( rFrom.GetRed() < rTo.GetRed() )
198 nDiff = rTo.GetRed() - rFrom.GetRed();
199 aColor.SetRed( rFrom.GetRed() + ( nDiff < 10 ? nDiff : 10 ) );
201 else if( rFrom.GetRed() > rTo.GetRed() )
203 nDiff = rFrom.GetRed() - rTo.GetRed();
204 aColor.SetRed( rFrom.GetRed() - ( nDiff < 10 ? nDiff : 10 ) );
206 else
207 aColor.SetRed( rFrom.GetRed() );
209 // approach Green
210 if( rFrom.GetGreen() < rTo.GetGreen() )
212 nDiff = rTo.GetGreen() - rFrom.GetGreen();
213 aColor.SetGreen( rFrom.GetGreen() + ( nDiff < 10 ? nDiff : 10 ) );
215 else if( rFrom.GetGreen() > rTo.GetGreen() )
217 nDiff = rFrom.GetGreen() - rTo.GetGreen();
218 aColor.SetGreen( rFrom.GetGreen() - ( nDiff < 10 ? nDiff : 10 ) );
220 else
221 aColor.SetGreen( rFrom.GetGreen() );
223 // approach blue
224 if( rFrom.GetBlue() < rTo.GetBlue() )
226 nDiff = rTo.GetBlue() - rFrom.GetBlue();
227 aColor.SetBlue( rFrom.GetBlue() + ( nDiff < 10 ? nDiff : 10 ) );
229 else if( rFrom.GetBlue() > rTo.GetBlue() )
231 nDiff = rFrom.GetBlue() - rTo.GetBlue();
232 aColor.SetBlue( rFrom.GetBlue() - ( nDiff < 10 ? nDiff : 10 ) );
234 else
235 aColor.SetBlue( rFrom.GetBlue() );
237 return aColor;
240 #define DELTA 5.0
241 void MyWin::Paint( const Rectangle& rRect )
243 WorkWindow::Paint( rRect );
245 Push( PUSH_ALL );
246 MapMode aMapMode( MAP_100TH_MM );
248 SetMapMode( aMapMode );
250 Size aPaperSize = GetOutputSize();
251 Point aCenter( aPaperSize.Width()/2-300,
252 (aPaperSize.Height() - 8400)/2 + 8400 );
253 Point aP1( aPaperSize.Width()/48, 0), aP2( aPaperSize.Width()/40, 0 ), aPoint;
255 DrawRect( Rectangle( Point( 0,0 ), aPaperSize ) );
256 DrawRect( Rectangle( Point( 100,100 ),
257 Size( aPaperSize.Width()-200,
258 aPaperSize.Height()-200 ) ) );
259 DrawRect( Rectangle( Point( 200,200 ),
260 Size( aPaperSize.Width()-400,
261 aPaperSize.Height()-400 ) ) );
262 DrawRect( Rectangle( Point( 300,300 ),
263 Size( aPaperSize.Width()-600,
264 aPaperSize.Height()-600 ) ) );
266 // AllSettings aSettings( Application::GetSettings() );
268 const int nFontCount = GetDevFontCount();
269 const int nFontSamples = (nFontCount<15) ? nFontCount : 15;
270 for( int i = 0; i < nFontSamples; ++i )
272 #if 0
273 Font aFont( GetFont() );
274 aFont.SetName( String( RTL_CONSTASCII_USTRINGPARAM( "Courier" ) ) );
275 aFont.SetWeight( WEIGHT_NORMAL );
276 aFont.SetItalic( ITALIC_NONE );
277 #else
278 FontInfo aFont = GetDevFont( (i*nFontCount) / nFontSamples );
279 aFont.SetHeight( 400 + (i%7) * 100 );
280 aFont.SetOrientation( i * (3600 / nFontSamples) );
281 #endif
282 SetFont( aFont );
284 sal_uInt8 nRed = (i << 6) & 0xC0;
285 sal_uInt8 nGreen = (i << 4) & 0xC0;
286 sal_uInt8 nBlue = (i << 2) & 0xC0;
287 SetTextColor( Color( nRed, nGreen, nBlue ) );
289 OUStringBuffer aPrintText(1024);
290 long nMaxWidth = 0;
292 aPrintText.appendAscii( "SVP test program" );
294 DrawText( Rectangle( Point( (aPaperSize.Width() - 4000) / 2, 2000 ),
295 Size( aPaperSize.Width() - 2100 - nMaxWidth,
296 aPaperSize.Height() - 4000 ) ),
297 aPrintText.makeStringAndClear(),
298 TEXT_DRAW_MULTILINE );
301 SetFillColor();
302 DrawRect( Rectangle( Point( aPaperSize.Width() - 4000, 1000 ),
303 Size( 3000,3000 ) ) );
304 DrawBitmap( Point( aPaperSize.Width() - 4000, 1000 ),
305 Size( 3000,3000 ),
306 m_aBitmap );
308 Color aWhite( 0xff, 0xff, 0xff );
309 Color aBlack( 0, 0, 0 );
310 Color aLightRed( 0xff, 0, 0 );
311 Color aDarkRed( 0x40, 0, 0 );
312 Color aLightBlue( 0, 0, 0xff );
313 Color aDarkBlue( 0,0,0x40 );
314 Color aLightGreen( 0, 0xff, 0 );
315 Color aDarkGreen( 0, 0x40, 0 );
317 Gradient aGradient( GRADIENT_LINEAR, aBlack, aWhite );
318 aGradient.SetAngle( 900 );
319 DrawGradient( Rectangle( Point( 1000, 4500 ),
320 Size( aPaperSize.Width() - 2000,
321 500 ) ), aGradient );
322 aGradient.SetStartColor( aDarkRed );
323 aGradient.SetEndColor( aLightBlue );
324 DrawGradient( Rectangle( Point( 1000, 5300 ),
325 Size( aPaperSize.Width() - 2000,
326 500 ) ), aGradient );
327 aGradient.SetStartColor( aDarkBlue );
328 aGradient.SetEndColor( aLightGreen );
329 DrawGradient( Rectangle( Point( 1000, 6100 ),
330 Size( aPaperSize.Width() - 2000,
331 500 ) ), aGradient );
332 aGradient.SetStartColor( aDarkGreen );
333 aGradient.SetEndColor( aLightRed );
334 DrawGradient( Rectangle( Point( 1000, 6900 ),
335 Size( aPaperSize.Width() - 2000,
336 500 ) ), aGradient );
340 LineInfo aLineInfo( LINE_SOLID, 200 );
341 double sind = sin( DELTA*M_PI/180.0 );
342 double cosd = cos( DELTA*M_PI/180.0 );
343 double factor = 1 + (DELTA/1000.0);
344 int n=0;
345 Color aLineColor( 0, 0, 0 );
346 Color aApproachColor( 0, 0, 200 );
347 while ( aP2.X() < aCenter.X() && n++ < 680 )
349 aLineInfo.SetWidth( n/3 );
350 aLineColor = approachColor( aLineColor, aApproachColor );
351 SetLineColor( aLineColor );
353 // switch aproach color
354 if( aApproachColor.IsRGBEqual( aLineColor ) )
356 if( aApproachColor.GetRed() )
357 aApproachColor = Color( 0, 0, 200 );
358 else if( aApproachColor.GetGreen() )
359 aApproachColor = Color( 200, 0, 0 );
360 else
361 aApproachColor = Color( 0, 200, 0 );
364 DrawLine( project( aP1 ) + aCenter,
365 project( aP2 ) + aCenter,
366 aLineInfo );
367 aPoint.X() = (int)((((double)aP1.X())*cosd - ((double)aP1.Y())*sind)*factor);
368 aPoint.Y() = (int)((((double)aP1.Y())*cosd + ((double)aP1.X())*sind)*factor);
369 aP1 = aPoint;
370 aPoint.X() = (int)((((double)aP2.X())*cosd - ((double)aP2.Y())*sind)*factor);
371 aPoint.Y() = (int)((((double)aP2.Y())*cosd + ((double)aP2.X())*sind)*factor);
372 aP2 = aPoint;
374 Pop();
377 // -----------------------------------------------------------------------
379 void MyWin::Resize()
381 WorkWindow::Resize();