Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <sal/main.h>
21 : #include <tools/extendapplicationenvironment.hxx>
22 :
23 : #include <cppuhelper/bootstrap.hxx>
24 : #include <comphelper/processfactory.hxx>
25 :
26 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
27 : #include <com/sun/star/uno/XComponentContext.hpp>
28 :
29 : #include <vcl/event.hxx>
30 : #include <vcl/svapp.hxx>
31 : #include <vcl/wrkwin.hxx>
32 : #include <vcl/msgbox.hxx>
33 :
34 : #include <unistd.h>
35 : #include <stdio.h>
36 :
37 : using namespace ::com::sun::star::uno;
38 : using namespace ::com::sun::star::lang;
39 : using namespace cppu;
40 :
41 : // Forward declaration
42 : void Main();
43 :
44 0 : SAL_IMPLEMENT_MAIN()
45 : {
46 0 : tools::extendApplicationEnvironment();
47 :
48 0 : Reference< XComponentContext > xContext = defaultBootstrap_InitialComponentContext();
49 0 : Reference< XMultiServiceFactory > xServiceManager( xContext->getServiceManager(), UNO_QUERY );
50 :
51 0 : if( !xServiceManager.is() )
52 0 : Application::Abort( "Failed to bootstrap" );
53 :
54 0 : comphelper::setProcessServiceFactory( xServiceManager );
55 :
56 0 : InitVCL();
57 0 : ::Main();
58 0 : DeInitVCL();
59 :
60 0 : return 0;
61 : }
62 :
63 0 : class MyWin : public WorkWindow
64 : {
65 : public:
66 : MyWin( vcl::Window* pParent, WinBits nWinStyle );
67 :
68 : virtual void MouseMove( const MouseEvent& rMEvt ) SAL_OVERRIDE;
69 : virtual void MouseButtonDown( const MouseEvent& rMEvt ) SAL_OVERRIDE;
70 : virtual void MouseButtonUp( const MouseEvent& rMEvt ) SAL_OVERRIDE;
71 : virtual void KeyInput( const KeyEvent& rKEvt ) SAL_OVERRIDE;
72 : virtual void KeyUp( const KeyEvent& rKEvt ) SAL_OVERRIDE;
73 : virtual void Paint( const Rectangle& rRect ) SAL_OVERRIDE;
74 : virtual void Resize() SAL_OVERRIDE;
75 : };
76 :
77 0 : void Main()
78 : {
79 0 : MyWin aMainWin( NULL, WB_APP | WB_STDWORK );
80 0 : aMainWin.SetText( OUString( "VCLDemo - VCL Workbench" ) );
81 0 : aMainWin.Show();
82 :
83 0 : Application::Execute();
84 0 : }
85 :
86 0 : MyWin::MyWin( vcl::Window* pParent, WinBits nWinStyle ) :
87 0 : WorkWindow( pParent, nWinStyle )
88 : {
89 0 : }
90 :
91 0 : void MyWin::MouseMove( const MouseEvent& rMEvt )
92 : {
93 0 : WorkWindow::MouseMove( rMEvt );
94 0 : }
95 :
96 0 : void MyWin::MouseButtonDown( const MouseEvent& rMEvt )
97 : {
98 0 : Rectangle aRect(0,0,4,4);
99 0 : aRect.SetPos( rMEvt.GetPosPixel() );
100 0 : SetFillColor(Color(COL_RED));
101 0 : DrawRect( aRect );
102 0 : }
103 :
104 0 : void MyWin::MouseButtonUp( const MouseEvent& rMEvt )
105 : {
106 0 : WorkWindow::MouseButtonUp( rMEvt );
107 0 : }
108 :
109 0 : void MyWin::KeyInput( const KeyEvent& rKEvt )
110 : {
111 0 : WorkWindow::KeyInput( rKEvt );
112 0 : }
113 :
114 0 : void MyWin::KeyUp( const KeyEvent& rKEvt )
115 : {
116 0 : WorkWindow::KeyUp( rKEvt );
117 0 : }
118 :
119 0 : void MyWin::Paint( const Rectangle& rRect )
120 : {
121 0 : fprintf(stderr, "MyWin::Paint(%ld,%ld,%ld,%ld)\n", rRect.getX(), rRect.getY(), rRect.getWidth(), rRect.getHeight());
122 :
123 0 : Size aSz(GetSizePixel());
124 0 : Point aPt;
125 0 : Rectangle r(aPt, aSz);
126 :
127 0 : SetFillColor(Color(COL_BLUE));
128 0 : SetLineColor(Color(COL_YELLOW));
129 :
130 0 : DrawRect( r );
131 :
132 0 : for(int i=0; i<aSz.Height(); i+=15)
133 0 : DrawLine( Point(r.Left(), r.Top()+i), Point(r.Right(), r.Bottom()-i) );
134 0 : for(int i=0; i<aSz.Width(); i+=15)
135 0 : DrawLine( Point(r.Left()+i, r.Bottom()), Point(r.Right()-i, r.Top()) );
136 :
137 0 : SetTextColor( Color( COL_WHITE ) );
138 0 : vcl::Font aFont( OUString( "Times" ), Size( 0, 25 ) );
139 0 : SetFont( aFont );
140 0 : DrawText( Point( 20, 30 ), OUString( "Just a simple test text" ) );
141 0 : }
142 :
143 0 : void MyWin::Resize()
144 : {
145 0 : WorkWindow::Resize();
146 0 : }
147 :
148 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|