LCOV - code coverage report
Current view: top level - libreoffice/UnoControls/source/base - basecontrol.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 298 0.0 %
Date: 2012-12-27 Functions: 0 65 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10