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