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

Generated by: LCOV version 1.11