Branch data 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 "basecontrol.hxx"
21 : :
22 : : #include <com/sun/star/awt/XDevice.hpp>
23 : : #include <com/sun/star/awt/XDisplayBitmap.hpp>
24 : : #include <com/sun/star/awt/DeviceInfo.hpp>
25 : : #include <com/sun/star/awt/WindowAttribute.hpp>
26 : : #include <com/sun/star/awt/PosSize.hpp>
27 : : #include <cppuhelper/typeprovider.hxx>
28 : :
29 : : //____________________________________________________________________________________________________________
30 : : // namespaces
31 : : //____________________________________________________________________________________________________________
32 : :
33 : : using namespace ::cppu ;
34 : : using namespace ::osl ;
35 : : using namespace ::rtl ;
36 : : using namespace ::com::sun::star::uno ;
37 : : using namespace ::com::sun::star::lang ;
38 : : using namespace ::com::sun::star::awt ;
39 : :
40 : : namespace unocontrols{
41 : :
42 : : #define DEFAULT_PMULTIPLEXER NULL
43 : : #define DEFAULT_X 0
44 : : #define DEFAULT_Y 0
45 : : #define DEFAULT_WIDTH 100
46 : : #define DEFAULT_HEIGHT 100
47 : : #define DEFAULT_VISIBLE sal_False
48 : : #define DEFAULT_INDESIGNMODE sal_False
49 : : #define DEFAULT_ENABLE sal_True
50 : : #define SERVICE_VCLTOOLKIT "com.sun.star.awt.Toolkit"
51 : :
52 : : //____________________________________________________________________________________________________________
53 : : // construct/destruct
54 : : //____________________________________________________________________________________________________________
55 : :
56 : 0 : BaseControl::BaseControl( const Reference< XMultiServiceFactory >& xFactory )
57 : : : IMPL_MutexContainer ( )
58 : : , OComponentHelper ( m_aMutex )
59 : : , m_xFactory ( xFactory )
60 : : , m_pMultiplexer ( DEFAULT_PMULTIPLEXER )
61 : : , m_nX ( DEFAULT_X )
62 : : , m_nY ( DEFAULT_Y )
63 : : , m_nWidth ( DEFAULT_WIDTH )
64 : : , m_nHeight ( DEFAULT_HEIGHT )
65 : : , m_bVisible ( DEFAULT_VISIBLE )
66 : : , m_bInDesignMode ( DEFAULT_INDESIGNMODE )
67 : 0 : , m_bEnable ( DEFAULT_ENABLE )
68 : : {
69 : 0 : }
70 : :
71 : 0 : BaseControl::~BaseControl()
72 : : {
73 : 0 : }
74 : :
75 : : //____________________________________________________________________________________________________________
76 : : // XInterface
77 : : //____________________________________________________________________________________________________________
78 : :
79 : 0 : Any SAL_CALL BaseControl::queryInterface( const Type& rType ) throw( RuntimeException )
80 : : {
81 : 0 : Any aReturn ;
82 : 0 : if ( m_xDelegator.is() == sal_True )
83 : : {
84 : : // If an delegator exist, forward question to his queryInterface.
85 : : // Delegator will ask his own queryAggregation!
86 : 0 : aReturn = m_xDelegator->queryInterface( rType );
87 : : }
88 : : else
89 : : {
90 : : // If an delegator unknown, forward question to own queryAggregation.
91 : 0 : aReturn = queryAggregation( rType );
92 : : }
93 : :
94 : 0 : return aReturn ;
95 : : }
96 : :
97 : : //____________________________________________________________________________________________________________
98 : : // XInterface
99 : : //____________________________________________________________________________________________________________
100 : :
101 : 0 : void SAL_CALL BaseControl::acquire() throw()
102 : : {
103 : : // Attention:
104 : : // Don't use mutex or guard in this method!!! Is a method of XInterface.
105 : :
106 : : // Forward to baseclass
107 : 0 : OComponentHelper::acquire();
108 : 0 : }
109 : :
110 : : //____________________________________________________________________________________________________________
111 : : // XInterface
112 : : //____________________________________________________________________________________________________________
113 : :
114 : 0 : void SAL_CALL BaseControl::release() throw()
115 : : {
116 : : // Attention:
117 : : // Don't use mutex or guard in this method!!! Is a method of XInterface.
118 : :
119 : : // Forward to baseclass
120 : 0 : OComponentHelper::release();
121 : 0 : }
122 : :
123 : : //____________________________________________________________________________________________________________
124 : : // XTypeProvider
125 : : //____________________________________________________________________________________________________________
126 : :
127 : 0 : Sequence< Type > SAL_CALL BaseControl::getTypes() throw( RuntimeException )
128 : : {
129 : : // Optimize this method !
130 : : // We initialize a static variable only one time. And we don't must use a mutex at every call!
131 : : // For the first call; pTypeCollection is NULL - for the second call pTypeCollection is different from NULL!
132 : : static OTypeCollection* pTypeCollection = NULL ;
133 : :
134 : 0 : if ( pTypeCollection == NULL )
135 : : {
136 : : // Ready for multithreading; get global mutex for first call of this method only! see before
137 : 0 : MutexGuard aGuard( Mutex::getGlobalMutex() );
138 : :
139 : : // Control these pointer again ... it can be, that another instance will be faster then these!
140 : 0 : if ( pTypeCollection == NULL )
141 : : {
142 : : // Create a static typecollection ...
143 : 0 : static OTypeCollection aTypeCollection( ::getCppuType(( const Reference< XPaintListener >*)NULL ) ,
144 : 0 : ::getCppuType(( const Reference< XWindowListener>*)NULL ) ,
145 : 0 : ::getCppuType(( const Reference< XView >*)NULL ) ,
146 : 0 : ::getCppuType(( const Reference< XWindow >*)NULL ) ,
147 : 0 : ::getCppuType(( const Reference< XServiceInfo >*)NULL ) ,
148 : 0 : ::getCppuType(( const Reference< XControl >*)NULL ) ,
149 : : OComponentHelper::getTypes()
150 : 0 : );
151 : :
152 : : // ... and set his address to static pointer!
153 : 0 : pTypeCollection = &aTypeCollection ;
154 : 0 : }
155 : : }
156 : :
157 : 0 : return pTypeCollection->getTypes();
158 : : }
159 : :
160 : : //____________________________________________________________________________________________________________
161 : : // XTypeProvider
162 : : //____________________________________________________________________________________________________________
163 : :
164 : 0 : Sequence< sal_Int8 > SAL_CALL BaseControl::getImplementationId() throw( RuntimeException )
165 : : {
166 : : // Create one Id for all instances of this class.
167 : : // Use ethernet address to do this! (sal_True)
168 : :
169 : : // Optimize this method
170 : : // We initialize a static variable only one time. And we don't must use a mutex at every call!
171 : : // For the first call; pID is NULL - for the second call pID is different from NULL!
172 : : static OImplementationId* pID = NULL ;
173 : :
174 : 0 : if ( pID == NULL )
175 : : {
176 : : // Ready for multithreading; get global mutex for first call of this method only! see before
177 : 0 : MutexGuard aGuard( Mutex::getGlobalMutex() );
178 : :
179 : : // Control these pointer again ... it can be, that another instance will be faster then these!
180 : 0 : if ( pID == NULL )
181 : : {
182 : : // Create a new static ID ...
183 : 0 : static OImplementationId aID( sal_False );
184 : : // ... and set his address to static pointer!
185 : 0 : pID = &aID ;
186 : 0 : }
187 : : }
188 : :
189 : 0 : return pID->getImplementationId();
190 : : }
191 : :
192 : : //____________________________________________________________________________________________________________
193 : : // XAggregation
194 : : //____________________________________________________________________________________________________________
195 : :
196 : 0 : void SAL_CALL BaseControl::setDelegator( const Reference< XInterface >& xDel ) throw( RuntimeException )
197 : : {
198 : : // Ready for multithreading
199 : 0 : MutexGuard aGuard( m_aMutex );
200 : 0 : m_xDelegator = xDel;
201 : 0 : }
202 : :
203 : : //____________________________________________________________________________________________________________
204 : : // XAggregation
205 : : //____________________________________________________________________________________________________________
206 : :
207 : 0 : Any SAL_CALL BaseControl::queryAggregation( const Type& aType ) throw( RuntimeException )
208 : : {
209 : : // Ask for my own supported interfaces ...
210 : : // Attention: XTypeProvider and XInterface are supported by OComponentHelper!
211 : : Any aReturn ( ::cppu::queryInterface( aType ,
212 : : static_cast< XPaintListener*> ( this ) ,
213 : : static_cast< XWindowListener*> ( this ) ,
214 : : static_cast< XView* > ( this ) ,
215 : : static_cast< XWindow* > ( this ) ,
216 : : static_cast< XServiceInfo* > ( this ) ,
217 : : static_cast< XControl* > ( this )
218 : : )
219 : 0 : );
220 : :
221 : : // If searched interface supported by this class ...
222 : 0 : if ( aReturn.hasValue() == sal_True )
223 : : {
224 : : // ... return this information.
225 : 0 : return aReturn ;
226 : : }
227 : : else
228 : : {
229 : : // Else; ... ask baseclass for interfaces!
230 : 0 : return OComponentHelper::queryAggregation( aType );
231 : 0 : }
232 : : }
233 : :
234 : : //____________________________________________________________________________________________________________
235 : : // XServiceInfo
236 : : //____________________________________________________________________________________________________________
237 : :
238 : 0 : OUString SAL_CALL BaseControl::getImplementationName() throw( RuntimeException )
239 : : {
240 : 0 : return impl_getStaticImplementationName();
241 : : }
242 : :
243 : : //____________________________________________________________________________________________________________
244 : : // XServiceInfo
245 : : //____________________________________________________________________________________________________________
246 : :
247 : 0 : sal_Bool SAL_CALL BaseControl::supportsService( const OUString& sServiceName ) throw( RuntimeException )
248 : : {
249 : 0 : Sequence< OUString > seqServiceNames = getSupportedServiceNames();
250 : 0 : const OUString* pArray = seqServiceNames.getConstArray();
251 : 0 : for ( sal_Int32 nCounter=0; nCounter<seqServiceNames.getLength(); nCounter++ )
252 : : {
253 : 0 : if ( pArray[nCounter] == sServiceName )
254 : : {
255 : 0 : return sal_True ;
256 : : }
257 : : }
258 : 0 : return sal_False ;
259 : : }
260 : :
261 : : //____________________________________________________________________________________________________________
262 : : // XServiceInfo
263 : : //____________________________________________________________________________________________________________
264 : :
265 : 0 : Sequence< OUString > SAL_CALL BaseControl::getSupportedServiceNames() throw( RuntimeException )
266 : : {
267 : 0 : return impl_getStaticSupportedServiceNames();
268 : : }
269 : :
270 : : //____________________________________________________________________________________________________________
271 : : // XComponent
272 : : //____________________________________________________________________________________________________________
273 : :
274 : 0 : void SAL_CALL BaseControl::dispose() throw( RuntimeException )
275 : : {
276 : : // Ready for multithreading
277 : 0 : MutexGuard aGuard( m_aMutex );
278 : :
279 : 0 : if ( m_pMultiplexer != NULL )
280 : : {
281 : : // to all other paint, focus, etc.
282 : 0 : m_pMultiplexer->disposeAndClear();
283 : : }
284 : :
285 : : // set the service manager to disposed
286 : 0 : OComponentHelper::dispose();
287 : :
288 : : // release context and peer
289 : 0 : m_xContext = Reference< XInterface >();
290 : 0 : impl_releasePeer();
291 : :
292 : : // release view
293 : 0 : if ( m_xGraphicsView.is() == sal_True )
294 : : {
295 : 0 : m_xGraphicsView = Reference< XGraphics >();
296 : 0 : }
297 : 0 : }
298 : :
299 : : //____________________________________________________________________________________________________________
300 : : // XComponent
301 : : //____________________________________________________________________________________________________________
302 : :
303 : 0 : void SAL_CALL BaseControl::addEventListener( const Reference< XEventListener >& xListener ) throw( RuntimeException )
304 : : {
305 : : // Ready for multithreading
306 : 0 : MutexGuard aGuard( m_aMutex );
307 : 0 : OComponentHelper::addEventListener( xListener );
308 : 0 : }
309 : :
310 : : //____________________________________________________________________________________________________________
311 : : // XComponent
312 : : //____________________________________________________________________________________________________________
313 : :
314 : 0 : void SAL_CALL BaseControl::removeEventListener( const Reference< XEventListener >& xListener ) throw( RuntimeException )
315 : : {
316 : : // Ready for multithreading
317 : 0 : MutexGuard aGuard( m_aMutex );
318 : 0 : OComponentHelper::removeEventListener( xListener );
319 : 0 : }
320 : :
321 : : //____________________________________________________________________________________________________________
322 : : // XControl
323 : : //____________________________________________________________________________________________________________
324 : :
325 : 0 : void SAL_CALL BaseControl::createPeer( const Reference< XToolkit >& xToolkit ,
326 : : const Reference< XWindowPeer >& xParentPeer ) throw( RuntimeException )
327 : : {
328 : : // Ready for multithreading
329 : 0 : MutexGuard aGuard( m_aMutex );
330 : :
331 : 0 : if ( m_xPeer.is() == sal_False )
332 : : {
333 : : // use method "BaseControl::getWindowDescriptor()" fot change window attributes !!!
334 : 0 : WindowDescriptor* pDescriptor = impl_getWindowDescriptor( xParentPeer );
335 : :
336 : 0 : if ( m_bVisible == sal_True )
337 : : {
338 : 0 : pDescriptor->WindowAttributes |= WindowAttribute::SHOW ;
339 : : }
340 : :
341 : : // very slow under remote conditions!
342 : : // create the window on the server
343 : 0 : Reference< XToolkit > xLocalToolkit = xToolkit ;
344 : 0 : if ( xLocalToolkit.is() == sal_False )
345 : : {
346 : : // but first create wellknown toolkit, if it not exist
347 : 0 : xLocalToolkit = Reference< XToolkit > ( m_xFactory->createInstance( SERVICE_VCLTOOLKIT ), UNO_QUERY );
348 : : }
349 : 0 : m_xPeer = xLocalToolkit->createWindow( *pDescriptor );
350 : 0 : m_xPeerWindow = Reference< XWindow >( m_xPeer, UNO_QUERY );
351 : :
352 : : // don't forget to release the memory!
353 : 0 : delete pDescriptor ;
354 : :
355 : 0 : if ( m_xPeerWindow.is() == sal_True )
356 : : {
357 : 0 : if ( m_pMultiplexer != NULL )
358 : : {
359 : 0 : m_pMultiplexer->setPeer( m_xPeerWindow );
360 : : }
361 : :
362 : : // create new referenz to xgraphics for painting on a peer
363 : : // and add a paint listener
364 : 0 : Reference< XDevice > xDevice( m_xPeerWindow, UNO_QUERY );
365 : :
366 : 0 : if ( xDevice.is() == sal_True )
367 : : {
368 : 0 : m_xGraphicsPeer = xDevice->createGraphics();
369 : : }
370 : :
371 : 0 : if ( m_xGraphicsPeer.is() == sal_True )
372 : : {
373 : 0 : addPaintListener( this );
374 : 0 : addWindowListener( this );
375 : : }
376 : :
377 : : // PosSize_POSSIZE defined in <stardiv/uno/awt/window.hxx>
378 : 0 : m_xPeerWindow->setPosSize( m_nX, m_nY, m_nWidth, m_nHeight, PosSize::POSSIZE );
379 : 0 : m_xPeerWindow->setEnable( m_bEnable );
380 : 0 : m_xPeerWindow->setVisible( m_bVisible && !m_bInDesignMode );
381 : 0 : }
382 : 0 : }
383 : 0 : }
384 : :
385 : : //____________________________________________________________________________________________________________
386 : : // XControl
387 : : //____________________________________________________________________________________________________________
388 : :
389 : 0 : void SAL_CALL BaseControl::setContext( const Reference< XInterface >& xContext ) throw( RuntimeException )
390 : : {
391 : : // Ready for multithreading
392 : 0 : MutexGuard aGuard( m_aMutex );
393 : 0 : m_xContext = xContext ;
394 : 0 : }
395 : :
396 : : //____________________________________________________________________________________________________________
397 : : // XControl
398 : : //____________________________________________________________________________________________________________
399 : :
400 : 0 : void SAL_CALL BaseControl::setDesignMode( sal_Bool bOn ) throw( RuntimeException )
401 : : {
402 : : // Ready for multithreading
403 : 0 : MutexGuard aGuard( m_aMutex );
404 : 0 : m_bInDesignMode = bOn ;
405 : 0 : }
406 : :
407 : : //____________________________________________________________________________________________________________
408 : : // XControl
409 : : //____________________________________________________________________________________________________________
410 : :
411 : 0 : Reference< XInterface > SAL_CALL BaseControl::getContext() throw( RuntimeException )
412 : : {
413 : : // Ready for multithreading
414 : 0 : MutexGuard aGuard( m_aMutex );
415 : 0 : return m_xContext ;
416 : : }
417 : :
418 : : //____________________________________________________________________________________________________________
419 : : // XControl
420 : : //____________________________________________________________________________________________________________
421 : :
422 : 0 : Reference< XWindowPeer > SAL_CALL BaseControl::getPeer() throw( RuntimeException )
423 : : {
424 : : // Ready for multithreading
425 : 0 : MutexGuard aGuard( m_aMutex );
426 : 0 : return m_xPeer ;
427 : : }
428 : :
429 : : //____________________________________________________________________________________________________________
430 : : // XControl
431 : : //____________________________________________________________________________________________________________
432 : :
433 : 0 : Reference< XView > SAL_CALL BaseControl::getView() throw( RuntimeException )
434 : : {
435 : : // Ready for multithreading
436 : 0 : MutexGuard aGuard( m_aMutex );
437 : 0 : return Reference< XView >( (OWeakObject*)this, UNO_QUERY );
438 : : }
439 : :
440 : : //____________________________________________________________________________________________________________
441 : : // XControl
442 : : //____________________________________________________________________________________________________________
443 : :
444 : 0 : sal_Bool SAL_CALL BaseControl::isDesignMode() throw( RuntimeException )
445 : : {
446 : : // Ready for multithreading
447 : 0 : MutexGuard aGuard( m_aMutex );
448 : 0 : return m_bInDesignMode ;
449 : : }
450 : :
451 : : //____________________________________________________________________________________________________________
452 : : // XControl
453 : : //____________________________________________________________________________________________________________
454 : :
455 : 0 : sal_Bool SAL_CALL BaseControl::isTransparent() throw( RuntimeException )
456 : : {
457 : 0 : return sal_False ;
458 : : }
459 : :
460 : : //____________________________________________________________________________________________________________
461 : : // XWindow
462 : : //____________________________________________________________________________________________________________
463 : :
464 : 0 : void SAL_CALL BaseControl::setPosSize( sal_Int32 nX ,
465 : : sal_Int32 nY ,
466 : : sal_Int32 nWidth ,
467 : : sal_Int32 nHeight ,
468 : : sal_Int16 nFlags ) throw( RuntimeException )
469 : : {
470 : : // - change size and position of window and save the values
471 : : // - "nFlags" declared in <stardiv/uno/awt/window.hxx> ("#define PosSize_X .....")
472 : :
473 : : // Ready for multithreading
474 : 0 : MutexGuard aGuard( m_aMutex );
475 : :
476 : 0 : sal_Bool bChanged = sal_False ;
477 : :
478 : 0 : if ( nFlags & PosSize::X )
479 : : {
480 : 0 : bChanged |= m_nX != nX, m_nX = nX ;
481 : : }
482 : :
483 : 0 : if ( nFlags & PosSize::Y )
484 : : {
485 : 0 : bChanged |= m_nY != nY, m_nY = nY ;
486 : : }
487 : :
488 : 0 : if ( nFlags & PosSize::WIDTH )
489 : : {
490 : 0 : bChanged |= m_nWidth != nWidth, m_nWidth = nWidth ;
491 : : }
492 : :
493 : 0 : if ( nFlags & PosSize::HEIGHT )
494 : : {
495 : 0 : bChanged |= m_nHeight != nHeight, m_nHeight = nHeight ;
496 : : }
497 : :
498 : 0 : if ( bChanged && m_xPeerWindow.is() )
499 : : {
500 : 0 : m_xPeerWindow->setPosSize( m_nX, m_nY, m_nWidth, m_nHeight, nFlags );
501 : 0 : }
502 : 0 : }
503 : :
504 : : //____________________________________________________________________________________________________________
505 : : // XWindow
506 : : //____________________________________________________________________________________________________________
507 : :
508 : 0 : void SAL_CALL BaseControl::setVisible( sal_Bool bVisible ) throw( RuntimeException )
509 : : {
510 : : // Ready for multithreading
511 : 0 : MutexGuard aGuard( m_aMutex );
512 : :
513 : : // Set new state of flag
514 : 0 : m_bVisible = bVisible ;
515 : :
516 : 0 : if ( m_xPeerWindow.is() == sal_True )
517 : : {
518 : : // Set it also on peerwindow
519 : 0 : m_xPeerWindow->setVisible( m_bVisible );
520 : 0 : }
521 : 0 : }
522 : :
523 : : //____________________________________________________________________________________________________________
524 : : // XWindow
525 : : //____________________________________________________________________________________________________________
526 : :
527 : 0 : void SAL_CALL BaseControl::setEnable( sal_Bool bEnable ) throw( RuntimeException )
528 : : {
529 : : // Ready for multithreading
530 : 0 : MutexGuard aGuard( m_aMutex );
531 : :
532 : : // Set new state of flag
533 : 0 : m_bEnable = bEnable ;
534 : :
535 : 0 : if ( m_xPeerWindow.is() == sal_True )
536 : : {
537 : : // Set it also on peerwindow
538 : 0 : m_xPeerWindow->setEnable( m_bEnable );
539 : 0 : }
540 : 0 : }
541 : :
542 : : //____________________________________________________________________________________________________________
543 : : // XWindow
544 : : //____________________________________________________________________________________________________________
545 : :
546 : 0 : void SAL_CALL BaseControl::setFocus() throw( RuntimeException )
547 : : {
548 : : // Ready for multithreading
549 : 0 : MutexGuard aGuard( m_aMutex );
550 : :
551 : 0 : if ( m_xPeerWindow.is() == sal_True )
552 : : {
553 : 0 : m_xPeerWindow->setFocus();
554 : 0 : }
555 : 0 : }
556 : :
557 : : //____________________________________________________________________________________________________________
558 : : // XWindow
559 : : //____________________________________________________________________________________________________________
560 : :
561 : 0 : Rectangle SAL_CALL BaseControl::getPosSize() throw( RuntimeException )
562 : : {
563 : : // Ready for multithreading
564 : 0 : MutexGuard aGuard( m_aMutex );
565 : 0 : return Rectangle( m_nX, m_nY , m_nWidth, m_nHeight );
566 : : }
567 : :
568 : : //____________________________________________________________________________________________________________
569 : : // XWindow
570 : : //____________________________________________________________________________________________________________
571 : :
572 : 0 : void SAL_CALL BaseControl::addWindowListener( const Reference< XWindowListener >& xListener ) throw( RuntimeException )
573 : : {
574 : 0 : impl_getMultiplexer()->advise( ::getCppuType(( const Reference< XWindowListener >*)0), xListener );
575 : 0 : }
576 : :
577 : : //____________________________________________________________________________________________________________
578 : : // XWindow
579 : : //____________________________________________________________________________________________________________
580 : :
581 : 0 : void SAL_CALL BaseControl::addFocusListener( const Reference< XFocusListener >& xListener ) throw( RuntimeException )
582 : : {
583 : 0 : impl_getMultiplexer()->advise( ::getCppuType(( const Reference< XFocusListener >*)0), xListener );
584 : 0 : }
585 : :
586 : : //____________________________________________________________________________________________________________
587 : : // XWindow
588 : : //____________________________________________________________________________________________________________
589 : :
590 : 0 : void SAL_CALL BaseControl::addKeyListener( const Reference< XKeyListener >& xListener ) throw( RuntimeException )
591 : : {
592 : 0 : impl_getMultiplexer()->advise( ::getCppuType(( const Reference< XKeyListener >*)0), xListener );
593 : 0 : }
594 : :
595 : : //____________________________________________________________________________________________________________
596 : : // XWindow
597 : : //____________________________________________________________________________________________________________
598 : :
599 : 0 : void SAL_CALL BaseControl::addMouseListener( const Reference< XMouseListener >& xListener ) throw( RuntimeException )
600 : : {
601 : 0 : impl_getMultiplexer()->advise( ::getCppuType(( const Reference< XMouseListener >*)0), xListener );
602 : 0 : }
603 : :
604 : : //____________________________________________________________________________________________________________
605 : : // XWindow
606 : : //____________________________________________________________________________________________________________
607 : :
608 : 0 : void SAL_CALL BaseControl::addMouseMotionListener( const Reference< XMouseMotionListener >& xListener ) throw( RuntimeException )
609 : : {
610 : 0 : impl_getMultiplexer()->advise( ::getCppuType(( const Reference< XMouseMotionListener >*)0), xListener );
611 : 0 : }
612 : :
613 : : //____________________________________________________________________________________________________________
614 : : // XWindow
615 : : //____________________________________________________________________________________________________________
616 : :
617 : 0 : void SAL_CALL BaseControl::addPaintListener( const Reference< XPaintListener >& xListener ) throw( RuntimeException )
618 : : {
619 : 0 : impl_getMultiplexer()->advise( ::getCppuType(( const Reference< XPaintListener >*)0), xListener );
620 : 0 : }
621 : :
622 : : //____________________________________________________________________________________________________________
623 : : // XWindow
624 : : //____________________________________________________________________________________________________________
625 : :
626 : 0 : void SAL_CALL BaseControl::removeWindowListener( const Reference< XWindowListener >& xListener ) throw( RuntimeException )
627 : : {
628 : 0 : impl_getMultiplexer()->unadvise( ::getCppuType(( const Reference< XWindowListener >*)0), xListener );
629 : 0 : }
630 : :
631 : : //____________________________________________________________________________________________________________
632 : : // XWindow
633 : : //____________________________________________________________________________________________________________
634 : :
635 : 0 : void SAL_CALL BaseControl::removeFocusListener( const Reference< XFocusListener >& xListener ) throw( RuntimeException )
636 : : {
637 : 0 : impl_getMultiplexer()->unadvise( ::getCppuType(( const Reference< XFocusListener >*)0), xListener );
638 : 0 : }
639 : :
640 : : //____________________________________________________________________________________________________________
641 : : // XWindow
642 : : //____________________________________________________________________________________________________________
643 : :
644 : 0 : void SAL_CALL BaseControl::removeKeyListener( const Reference< XKeyListener >& xListener ) throw( RuntimeException )
645 : : {
646 : 0 : impl_getMultiplexer()->unadvise( ::getCppuType(( const Reference< XKeyListener >*)0), xListener );
647 : 0 : }
648 : :
649 : : //____________________________________________________________________________________________________________
650 : : // XWindow
651 : : //____________________________________________________________________________________________________________
652 : :
653 : 0 : void SAL_CALL BaseControl::removeMouseListener( const Reference< XMouseListener >& xListener ) throw( RuntimeException )
654 : : {
655 : 0 : impl_getMultiplexer()->unadvise( ::getCppuType(( const Reference< XMouseListener >*)0), xListener );
656 : 0 : }
657 : :
658 : : //____________________________________________________________________________________________________________
659 : : // XWindow
660 : : //____________________________________________________________________________________________________________
661 : :
662 : 0 : void SAL_CALL BaseControl::removeMouseMotionListener( const Reference< XMouseMotionListener >& xListener ) throw( RuntimeException )
663 : : {
664 : 0 : impl_getMultiplexer()->unadvise( ::getCppuType(( const Reference< XMouseMotionListener >*)0), xListener );
665 : 0 : }
666 : :
667 : : //____________________________________________________________________________________________________________
668 : : // XWindow
669 : : //____________________________________________________________________________________________________________
670 : :
671 : 0 : void SAL_CALL BaseControl::removePaintListener( const Reference< XPaintListener >& xListener ) throw( RuntimeException )
672 : : {
673 : 0 : impl_getMultiplexer()->unadvise( ::getCppuType(( const Reference< XPaintListener >*)0), xListener );
674 : 0 : }
675 : :
676 : : //____________________________________________________________________________________________________________
677 : : // XView
678 : : //____________________________________________________________________________________________________________
679 : :
680 : 0 : void SAL_CALL BaseControl::draw( sal_Int32 nX ,
681 : : sal_Int32 nY ) throw( RuntimeException )
682 : : {
683 : : // Ready for multithreading
684 : 0 : MutexGuard aGuard( m_aMutex );
685 : :
686 : : // - paint to an view
687 : : // - use the method "paint()"
688 : : // - see also "windowPaint()"
689 : 0 : impl_paint( nX, nY, m_xGraphicsView );
690 : 0 : }
691 : :
692 : : //____________________________________________________________________________________________________________
693 : : // XView
694 : : //____________________________________________________________________________________________________________
695 : :
696 : 0 : sal_Bool SAL_CALL BaseControl::setGraphics( const Reference< XGraphics >& xDevice ) throw( RuntimeException )
697 : : {
698 : : // - set the graphics for an view
699 : : // - in this class exist 2 graphics-member ... one for peer[_xGraphicsPeer] and one for view[_xGraphicsView]
700 : : // - they are used by "windowPaint() and draw()", forwarded to "paint ()"
701 : 0 : sal_Bool bReturn = sal_False ;
702 : 0 : if ( xDevice.is() == sal_True )
703 : : {
704 : : // Ready for multithreading
705 : 0 : MutexGuard aGuard( m_aMutex );
706 : :
707 : 0 : m_xGraphicsView = xDevice ;
708 : 0 : bReturn = sal_True ;
709 : : }
710 : :
711 : 0 : return bReturn ;
712 : : }
713 : :
714 : : //____________________________________________________________________________________________________________
715 : : // XView
716 : : //____________________________________________________________________________________________________________
717 : :
718 : 0 : void SAL_CALL BaseControl::setZoom( float /*fZoomX*/ ,
719 : : float /*fZoomY*/ ) throw( RuntimeException )
720 : : {
721 : : // Not implemented yet
722 : 0 : }
723 : :
724 : : //____________________________________________________________________________________________________________
725 : : // XView
726 : : //____________________________________________________________________________________________________________
727 : :
728 : 0 : Reference< XGraphics > SAL_CALL BaseControl::getGraphics() throw( RuntimeException )
729 : : {
730 : : // Ready for multithreading
731 : 0 : MutexGuard aGuard( m_aMutex );
732 : 0 : return m_xGraphicsView ;
733 : : }
734 : :
735 : : //____________________________________________________________________________________________________________
736 : : // XView
737 : : //____________________________________________________________________________________________________________
738 : :
739 : 0 : Size SAL_CALL BaseControl::getSize() throw( RuntimeException )
740 : : {
741 : : // Ready for multithreading
742 : 0 : MutexGuard aGuard( m_aMutex );
743 : 0 : return Size( m_nWidth, m_nHeight );
744 : : }
745 : :
746 : : //____________________________________________________________________________________________________________
747 : : // XEventListener
748 : : //____________________________________________________________________________________________________________
749 : :
750 : 0 : void SAL_CALL BaseControl::disposing( const EventObject& /*aSource*/ ) throw( RuntimeException )
751 : : {
752 : : // Ready for multithreading
753 : 0 : MutexGuard aGuard( m_aMutex );
754 : :
755 : : // - release ALL references
756 : : // - it must be !!!
757 : 0 : if ( m_xGraphicsPeer.is() == sal_True )
758 : : {
759 : 0 : removePaintListener( this );
760 : 0 : removeWindowListener( this );
761 : 0 : m_xGraphicsPeer = Reference< XGraphics >();
762 : : }
763 : :
764 : 0 : if ( m_xGraphicsView.is() == sal_True )
765 : : {
766 : 0 : m_xGraphicsView = Reference< XGraphics >();
767 : 0 : }
768 : 0 : }
769 : :
770 : : //____________________________________________________________________________________________________________
771 : : // XPaintListener
772 : : //____________________________________________________________________________________________________________
773 : :
774 : 0 : void SAL_CALL BaseControl::windowPaint( const PaintEvent& /*aEvent*/ ) throw( RuntimeException )
775 : : {
776 : : // Ready for multithreading
777 : 0 : MutexGuard aGuard( m_aMutex );
778 : :
779 : : // - repaint the peer
780 : : // - use the method "paint ()" for painting on a peer and a print device !!!
781 : : // - see also "draw ()"
782 : 0 : impl_paint( 0, 0, m_xGraphicsPeer );
783 : 0 : }
784 : :
785 : : //____________________________________________________________________________________________________________
786 : : // XWindowListener
787 : : //____________________________________________________________________________________________________________
788 : :
789 : 0 : void SAL_CALL BaseControl::windowResized( const WindowEvent& aEvent ) throw( RuntimeException )
790 : : {
791 : : // Ready for multithreading
792 : 0 : MutexGuard aGuard( m_aMutex );
793 : :
794 : 0 : m_nWidth = aEvent.Width ;
795 : 0 : m_nHeight = aEvent.Height ;
796 : 0 : WindowEvent aMappedEvent = aEvent;
797 : 0 : aMappedEvent.X = 0;
798 : 0 : aMappedEvent.Y = 0;
799 : 0 : impl_recalcLayout( aMappedEvent );
800 : 0 : }
801 : :
802 : : //____________________________________________________________________________________________________________
803 : : // XWindowListener
804 : : //____________________________________________________________________________________________________________
805 : :
806 : 0 : void SAL_CALL BaseControl::windowMoved( const WindowEvent& aEvent ) throw( RuntimeException )
807 : : {
808 : : // Ready for multithreading
809 : 0 : MutexGuard aGuard( m_aMutex );
810 : :
811 : 0 : m_nWidth = aEvent.Width ;
812 : 0 : m_nHeight = aEvent.Height ;
813 : 0 : WindowEvent aMappedEvent = aEvent;
814 : 0 : aMappedEvent.X = 0;
815 : 0 : aMappedEvent.Y = 0;
816 : 0 : impl_recalcLayout( aMappedEvent );
817 : 0 : }
818 : :
819 : : //____________________________________________________________________________________________________________
820 : : // XWindowListener
821 : : //____________________________________________________________________________________________________________
822 : :
823 : 0 : void SAL_CALL BaseControl::windowShown( const EventObject& /*aEvent*/ ) throw( RuntimeException )
824 : : {
825 : 0 : }
826 : :
827 : : //____________________________________________________________________________________________________________
828 : : // XWindowListener
829 : : //____________________________________________________________________________________________________________
830 : :
831 : 0 : void SAL_CALL BaseControl::windowHidden( const EventObject& /*aEvent*/ ) throw( RuntimeException )
832 : : {
833 : 0 : }
834 : :
835 : : //____________________________________________________________________________________________________________
836 : : // impl but public method to register service in DLL
837 : : // (In this BASE-implementation not implemented! Overwrite it in derived classes.)
838 : : //____________________________________________________________________________________________________________
839 : :
840 : 0 : const Sequence< OUString > BaseControl::impl_getStaticSupportedServiceNames()
841 : : {
842 : 0 : return Sequence< OUString >();
843 : : }
844 : :
845 : : //____________________________________________________________________________________________________________
846 : : // impl but public method to register service in DLL
847 : : // (In this BASE-implementation not implemented! Overwrite it in derived classes.)
848 : : //____________________________________________________________________________________________________________
849 : :
850 : 0 : const OUString BaseControl::impl_getStaticImplementationName()
851 : : {
852 : 0 : return OUString();
853 : : }
854 : :
855 : : //____________________________________________________________________________________________________________
856 : : // protected method
857 : : //____________________________________________________________________________________________________________
858 : :
859 : 0 : const Reference< XMultiServiceFactory > BaseControl::impl_getMultiServiceFactory()
860 : : {
861 : 0 : return m_xFactory ;
862 : : }
863 : :
864 : : //____________________________________________________________________________________________________________
865 : : // protected method
866 : : //____________________________________________________________________________________________________________
867 : :
868 : 0 : const Reference< XWindow > BaseControl::impl_getPeerWindow()
869 : : {
870 : 0 : return m_xPeerWindow ;
871 : : }
872 : :
873 : : //____________________________________________________________________________________________________________
874 : : // protected method
875 : : //____________________________________________________________________________________________________________
876 : :
877 : 0 : const Reference< XGraphics > BaseControl::impl_getGraphicsPeer()
878 : : {
879 : 0 : return m_xGraphicsPeer ;
880 : : }
881 : :
882 : : //____________________________________________________________________________________________________________
883 : : // protected method
884 : : //____________________________________________________________________________________________________________
885 : :
886 : 0 : const sal_Int32& BaseControl::impl_getWidth()
887 : : {
888 : 0 : return m_nWidth ;
889 : : }
890 : :
891 : : //____________________________________________________________________________________________________________
892 : : // protected method
893 : : //____________________________________________________________________________________________________________
894 : :
895 : 0 : const sal_Int32& BaseControl::impl_getHeight()
896 : : {
897 : 0 : return m_nHeight ;
898 : : }
899 : :
900 : : //____________________________________________________________________________________________________________
901 : : // protected method
902 : : //____________________________________________________________________________________________________________
903 : :
904 : 0 : WindowDescriptor* BaseControl::impl_getWindowDescriptor( const Reference< XWindowPeer >& xParentPeer )
905 : : {
906 : : // - used from "createPeer()" to set the values of an ::com::sun::star::awt::WindowDescriptor !!!
907 : : // - if you will change the descriptor-values, you must override this virtuell function
908 : : // - the caller must release the memory for this dynamical descriptor !!!
909 : :
910 : 0 : WindowDescriptor* pDescriptor = new WindowDescriptor ;
911 : :
912 : 0 : pDescriptor->Type = WindowClass_SIMPLE ;
913 : 0 : pDescriptor->WindowServiceName = "window" ;
914 : 0 : pDescriptor->ParentIndex = -1 ;
915 : 0 : pDescriptor->Parent = xParentPeer ;
916 : 0 : pDescriptor->Bounds = getPosSize () ;
917 : 0 : pDescriptor->WindowAttributes = 0 ;
918 : :
919 : 0 : return pDescriptor ;
920 : : }
921 : :
922 : : //____________________________________________________________________________________________________________
923 : : // protected method
924 : : //____________________________________________________________________________________________________________
925 : :
926 : 0 : void BaseControl::impl_paint( sal_Int32 /*nX*/ ,
927 : : sal_Int32 /*nY*/ ,
928 : : const Reference< XGraphics >& /*xGraphics*/ )
929 : : {
930 : : // - one paint method for peer AND view !!!
931 : : // (see also => "windowPaint()" and "draw()")
932 : : // - not used in this implementation, but its not necessary to make it pure virtual !!!
933 : 0 : }
934 : :
935 : : //____________________________________________________________________________________________________________
936 : : // protected method
937 : : //____________________________________________________________________________________________________________
938 : :
939 : 0 : void BaseControl::impl_recalcLayout( const WindowEvent& /*aEvent*/ )
940 : : {
941 : : // We need as virtual function to support automaticly resizing of derived controls!
942 : : // But we make it not pure virtual because it's not neccessary for all derived classes!
943 : 0 : }
944 : :
945 : : //____________________________________________________________________________________________________________
946 : : // protected method
947 : : //____________________________________________________________________________________________________________
948 : :
949 : 0 : Reference< XInterface > BaseControl::impl_getDelegator()
950 : : {
951 : 0 : return m_xDelegator ;
952 : : }
953 : :
954 : : //____________________________________________________________________________________________________________
955 : : // private method
956 : : //____________________________________________________________________________________________________________
957 : :
958 : 0 : void BaseControl::impl_releasePeer()
959 : : {
960 : 0 : if ( m_xPeer.is() == sal_True )
961 : : {
962 : 0 : if ( m_xGraphicsPeer.is() == sal_True )
963 : : {
964 : 0 : removePaintListener( this );
965 : 0 : removeWindowListener( this );
966 : 0 : m_xGraphicsPeer = Reference< XGraphics >();
967 : : }
968 : :
969 : 0 : m_xPeer->dispose();
970 : 0 : m_xPeerWindow = Reference< XWindow >();
971 : 0 : m_xPeer = Reference< XWindowPeer >();
972 : :
973 : 0 : if ( m_pMultiplexer != NULL )
974 : : {
975 : : // take changes on multiplexer
976 : 0 : m_pMultiplexer->setPeer( Reference< XWindow >() );
977 : : }
978 : : }
979 : 0 : }
980 : :
981 : : //____________________________________________________________________________________________________________
982 : : // private method
983 : : //____________________________________________________________________________________________________________
984 : :
985 : 0 : OMRCListenerMultiplexerHelper* BaseControl::impl_getMultiplexer()
986 : : {
987 : 0 : if ( m_pMultiplexer == NULL )
988 : : {
989 : 0 : m_pMultiplexer = new OMRCListenerMultiplexerHelper( (XWindow*)this, m_xPeerWindow );
990 : 0 : m_xMultiplexer = Reference< XInterface >( (OWeakObject*)m_pMultiplexer, UNO_QUERY );
991 : : }
992 : :
993 : 0 : return m_pMultiplexer ;
994 : : }
995 : :
996 : : } // namespace unocontrols
997 : :
998 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|