1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svtools.hxx"
26 #include <com/sun/star/embed/XHatchWindowController.hpp>
27
28 #include "hatchwindow.hxx"
29 #include "ipwin.hxx"
30
31 #include <toolkit/helper/convert.hxx>
32 #include <vos/mutex.hxx>
33 #include <vcl/svapp.hxx>
34
35 using namespace ::com::sun::star;
36
VCLXHatchWindow()37 VCLXHatchWindow::VCLXHatchWindow()
38 : VCLXWindow()
39 , pHatchWindow(0)
40 {
41 }
42
~VCLXHatchWindow()43 VCLXHatchWindow::~VCLXHatchWindow()
44 {
45 }
46
initializeWindow(const uno::Reference<awt::XWindowPeer> & xParent,const awt::Rectangle & aBounds,const awt::Size & aSize)47 void VCLXHatchWindow::initializeWindow( const uno::Reference< awt::XWindowPeer >& xParent,
48 const awt::Rectangle& aBounds,
49 const awt::Size& aSize )
50 {
51 ::vos::OGuard aGuard( Application::GetSolarMutex() );
52
53 Window* pParent = NULL;
54 VCLXWindow* pParentComponent = VCLXWindow::GetImplementation( xParent );
55
56 if ( pParentComponent )
57 pParent = pParentComponent->GetWindow();
58
59 OSL_ENSURE( pParent, "No parent window is provided!\n" );
60 if ( !pParent )
61 throw lang::IllegalArgumentException(); // TODO
62
63 pHatchWindow = new SvResizeWindow( pParent, this );
64 pHatchWindow->SetPosSizePixel( aBounds.X, aBounds.Y, aBounds.Width, aBounds.Height );
65 aHatchBorderSize = aSize;
66 pHatchWindow->SetHatchBorderPixel( Size( aSize.Width, aSize.Height ) );
67
68 SetWindow( pHatchWindow );
69 pHatchWindow->SetComponentInterface( this );
70
71 //pHatchWindow->Show();
72 }
73
QueryObjAreaPixel(Rectangle & aRect)74 void VCLXHatchWindow::QueryObjAreaPixel( Rectangle & aRect )
75 {
76 if ( m_xController.is() )
77 {
78 awt::Rectangle aUnoRequestRect = AWTRectangle( aRect );
79
80 try {
81 awt::Rectangle aUnoResultRect = m_xController->calcAdjustedRectangle( aUnoRequestRect );
82 aRect = VCLRectangle( aUnoResultRect );
83 }
84 catch( uno::Exception& )
85 {
86 OSL_ENSURE( sal_False, "Can't adjust rectangle size!\n" );
87 }
88 }
89 }
90
RequestObjAreaPixel(const Rectangle & aRect)91 void VCLXHatchWindow::RequestObjAreaPixel( const Rectangle & aRect )
92 {
93 if ( m_xController.is() )
94 {
95 awt::Rectangle aUnoRequestRect = AWTRectangle( aRect );
96
97 try {
98 m_xController->requestPositioning( aUnoRequestRect );
99 }
100 catch( uno::Exception& )
101 {
102 OSL_ENSURE( sal_False, "Can't request resizing!\n" );
103 }
104 }
105 }
106
InplaceDeactivate()107 void VCLXHatchWindow::InplaceDeactivate()
108 {
109 if ( m_xController.is() )
110 {
111 // TODO: communicate with controller
112 }
113 }
114
115
queryInterface(const uno::Type & rType)116 uno::Any SAL_CALL VCLXHatchWindow::queryInterface( const uno::Type & rType )
117 {
118 // Attention:
119 // Don't use mutex or guard in this method!!! Is a method of XInterface.
120
121 uno::Any aReturn( ::cppu::queryInterface( rType,
122 static_cast< embed::XHatchWindow* >( this ) ) );
123
124 if ( aReturn.hasValue() == sal_True )
125 {
126 return aReturn ;
127 }
128
129 return VCLXWindow::queryInterface( rType ) ;
130 }
131
acquire()132 void SAL_CALL VCLXHatchWindow::acquire()
133 throw()
134 {
135 VCLXWindow::acquire();
136 }
137
release()138 void SAL_CALL VCLXHatchWindow::release()
139 throw()
140 {
141 VCLXWindow::release();
142 }
143
getTypes()144 uno::Sequence< uno::Type > SAL_CALL VCLXHatchWindow::getTypes()
145 {
146 static ::cppu::OTypeCollection* pTypeCollection = NULL ;
147
148 if ( pTypeCollection == NULL )
149 {
150 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ) ;
151
152 if ( pTypeCollection == NULL )
153 {
154 static ::cppu::OTypeCollection aTypeCollection(
155 ::getCppuType(( const uno::Reference< embed::XHatchWindow >* )NULL ),
156 VCLXHatchWindow::getTypes() );
157
158 pTypeCollection = &aTypeCollection ;
159 }
160 }
161
162 return pTypeCollection->getTypes() ;
163 }
164
getImplementationId()165 uno::Sequence< sal_Int8 > SAL_CALL VCLXHatchWindow::getImplementationId()
166 {
167 static ::cppu::OImplementationId* pID = NULL ;
168
169 if ( pID == NULL )
170 {
171 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ) ;
172
173 if ( pID == NULL )
174 {
175 static ::cppu::OImplementationId aID( sal_False ) ;
176 pID = &aID ;
177 }
178 }
179
180 return pID->getImplementationId() ;
181 }
182
getHatchBorderSize()183 ::com::sun::star::awt::Size SAL_CALL VCLXHatchWindow::getHatchBorderSize()
184 {
185 return aHatchBorderSize;
186 }
187
setHatchBorderSize(const::com::sun::star::awt::Size & _hatchbordersize)188 void SAL_CALL VCLXHatchWindow::setHatchBorderSize( const ::com::sun::star::awt::Size& _hatchbordersize )
189 {
190 if ( pHatchWindow )
191 {
192 aHatchBorderSize = _hatchbordersize;
193 pHatchWindow->SetHatchBorderPixel( Size( aHatchBorderSize.Width, aHatchBorderSize.Height ) );
194 }
195 }
196
setController(const uno::Reference<embed::XHatchWindowController> & xController)197 void SAL_CALL VCLXHatchWindow::setController( const uno::Reference< embed::XHatchWindowController >& xController )
198 {
199 m_xController = xController;
200 }
201
dispose()202 void SAL_CALL VCLXHatchWindow::dispose()
203 {
204 pHatchWindow = 0;
205 VCLXWindow::dispose();
206 }
207
addEventListener(const uno::Reference<lang::XEventListener> & xListener)208 void SAL_CALL VCLXHatchWindow::addEventListener( const uno::Reference< lang::XEventListener >& xListener )
209 {
210 VCLXWindow::addEventListener( xListener );
211 }
212
removeEventListener(const uno::Reference<lang::XEventListener> & xListener)213 void SAL_CALL VCLXHatchWindow::removeEventListener( const uno::Reference< lang::XEventListener >& xListener )
214 {
215 VCLXWindow::removeEventListener( xListener );
216 }
217
Activated()218 void VCLXHatchWindow::Activated()
219 {
220 if ( m_xController.is() )
221 m_xController->activated();
222 }
223
Deactivated()224 void VCLXHatchWindow::Deactivated()
225 {
226 if ( m_xController.is() )
227 m_xController->deactivated();
228 }
229