xref: /aoo41x/main/vcl/workben/vcldemo.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_vcl.hxx"
30 
31 #include <sal/main.h>
32 #include <tools/extendapplicationenvironment.hxx>
33 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
34 
35 #include <vcl/event.hxx>
36 #include <vcl/svapp.hxx>
37 #include <vcl/wrkwin.hxx>
38 #include <vcl/msgbox.hxx>
39 #include <vcl/introwin.hxx>
40 #include <vcl/msgbox.hxx>
41 
42 #include <comphelper/processfactory.hxx>
43 #include <cppuhelper/servicefactory.hxx>
44 #include <cppuhelper/bootstrap.hxx>
45 
46 #include <unistd.h>
47 #include <stdio.h>
48 
49 using namespace ::com::sun::star::uno;
50 using namespace ::com::sun::star::lang;
51 // -----------------------------------------------------------------------
52 
53 // Forward declaration
54 void Main();
55 
56 // -----------------------------------------------------------------------
57 
58 SAL_IMPLEMENT_MAIN()
59 {
60     tools::extendApplicationEnvironment();
61 
62     Reference< XMultiServiceFactory > xMS;
63     xMS = cppu::createRegistryServiceFactory( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "types.rdb" ) ), rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "applicat.rdb" ) ), sal_True );
64 
65     InitVCL( xMS );
66     ::Main();
67     DeInitVCL();
68 
69     return 0;
70 }
71 
72 // -----------------------------------------------------------------------
73 
74 class MyWin : public WorkWindow
75 {
76 public:
77 				MyWin( Window* pParent, WinBits nWinStyle );
78 
79 	void		MouseMove( const MouseEvent& rMEvt );
80 	void		MouseButtonDown( const MouseEvent& rMEvt );
81 	void		MouseButtonUp( const MouseEvent& rMEvt );
82 	void		KeyInput( const KeyEvent& rKEvt );
83 	void		KeyUp( const KeyEvent& rKEvt );
84 	void		Paint( const Rectangle& rRect );
85 	void		Resize();
86 };
87 
88 // -----------------------------------------------------------------------
89 
90 void Main()
91 {
92     /*
93     IntroWindow splash;
94     splash.Show();
95     sleep(5);
96     splash.Hide();
97     */
98 
99 	MyWin aMainWin( NULL, WB_APP | WB_STDWORK );
100 	aMainWin.SetText( XubString( RTL_CONSTASCII_USTRINGPARAM( "VCLDemo - VCL Workbench" ) ) );
101 	aMainWin.Show();
102 
103     /*
104     InfoBox ib(NULL, String((sal_Char*)"Test", sizeof("Test")));
105     ib.Execute();
106     */
107 
108 	Application::Execute();
109 }
110 
111 // -----------------------------------------------------------------------
112 
113 MyWin::MyWin( Window* pParent, WinBits nWinStyle ) :
114 	WorkWindow( pParent, nWinStyle )
115 {
116 }
117 
118 // -----------------------------------------------------------------------
119 
120 void MyWin::MouseMove( const MouseEvent& rMEvt )
121 {
122 	WorkWindow::MouseMove( rMEvt );
123 }
124 
125 // -----------------------------------------------------------------------
126 
127 void MyWin::MouseButtonDown( const MouseEvent& rMEvt )
128 {
129     Rectangle aRect(0,0,4,4);
130 	aRect.SetPos( rMEvt.GetPosPixel() );
131 	SetFillColor(Color(COL_RED));
132 	DrawRect( aRect );
133 }
134 
135 // -----------------------------------------------------------------------
136 
137 void MyWin::MouseButtonUp( const MouseEvent& rMEvt )
138 {
139     WorkWindow::MouseButtonUp( rMEvt );
140 }
141 
142 // -----------------------------------------------------------------------
143 
144 void MyWin::KeyInput( const KeyEvent& rKEvt )
145 {
146 	WorkWindow::KeyInput( rKEvt );
147 }
148 
149 // -----------------------------------------------------------------------
150 
151 void MyWin::KeyUp( const KeyEvent& rKEvt )
152 {
153 	WorkWindow::KeyUp( rKEvt );
154 }
155 
156 // -----------------------------------------------------------------------
157 
158 void MyWin::Paint( const Rectangle& rRect )
159 {
160 	fprintf(stderr, "MyWin::Paint(%ld,%ld,%ld,%ld)\n", rRect.getX(), rRect.getY(), rRect.getWidth(), rRect.getHeight());
161 
162     Size aSz(GetSizePixel());
163     Point aPt;
164     Rectangle r(aPt, aSz);
165 
166 	SetFillColor(Color(COL_BLUE));
167     SetLineColor(Color(COL_YELLOW));
168 
169 	DrawRect( r );
170 
171     for(int i=0; i<aSz.Height(); i+=15)
172         DrawLine( Point(r.nLeft, r.nTop+i), Point(r.nRight, r.nBottom-i) );
173     for(int i=0; i<aSz.Width(); i+=15)
174         DrawLine( Point(r.nLeft+i, r.nBottom), Point(r.nRight-i, r.nTop) );
175 
176     SetTextColor( Color( COL_WHITE ) );
177     Font aFont( String( RTL_CONSTASCII_USTRINGPARAM( "Times" ) ), Size( 0, 25 ) );
178     SetFont( aFont );
179     DrawText( Point( 20, 30 ), String( RTL_CONSTASCII_USTRINGPARAM( "Just a simple test text" ) ) );
180 }
181 
182 // -----------------------------------------------------------------------
183 
184 void MyWin::Resize()
185 {
186 	WorkWindow::Resize();
187 }
188