LCOV - code coverage report
Current view: top level - UnoControls/source/controls - statusindicator.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 165 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 26 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 "statusindicator.hxx"
      21             : 
      22             : #include <com/sun/star/awt/WindowAttribute.hpp>
      23             : #include <com/sun/star/uno/XComponentContext.hpp>
      24             : #include <cppuhelper/queryinterface.hxx>
      25             : #include <cppuhelper/typeprovider.hxx>
      26             : 
      27             : #include "progressbar.hxx"
      28             : 
      29             : using namespace ::cppu;
      30             : using namespace ::osl;
      31             : using namespace ::com::sun::star::uno;
      32             : using namespace ::com::sun::star::lang;
      33             : using namespace ::com::sun::star::awt;
      34             : using namespace ::com::sun::star::task;
      35             : 
      36             : namespace unocontrols{
      37             : 
      38             : //  construct/destruct
      39             : 
      40           0 : StatusIndicator::StatusIndicator( const css::uno::Reference< XComponentContext >& rxContext )
      41           0 :     : BaseContainerControl  ( rxContext  )
      42             : {
      43             :     // Its not allowed to work with member in this method (refcounter !!!)
      44             :     // But with a HACK (++refcount) its "OK" :-(
      45           0 :     ++m_refCount;
      46             : 
      47             :     // Create instances for fixedtext and progress ...
      48           0 :     m_xText         = css::uno::Reference< XFixedText >   ( rxContext->getServiceManager()->createInstanceWithContext( FIXEDTEXT_SERVICENAME, rxContext ), UNO_QUERY );
      49           0 :     m_xProgressBar = VclPtr<ProgressBar>::Create(rxContext);
      50             :     // ... cast controls to css::uno::Reference< XControl > and set model ...
      51             :     // ( ProgressBar has no model !!! )
      52           0 :     css::uno::Reference< XControl > xTextControl      ( m_xText       , UNO_QUERY );
      53           0 :     xTextControl->setModel( css::uno::Reference< XControlModel >( rxContext->getServiceManager()->createInstanceWithContext( FIXEDTEXT_MODELNAME, rxContext ), UNO_QUERY ) );
      54             :     // ... and add controls to basecontainercontrol!
      55           0 :     addControl( CONTROLNAME_TEXT, xTextControl    );
      56           0 :     addControl( CONTROLNAME_PROGRESSBAR, m_xProgressBar.get() );
      57             :     // FixedText make it automatically visible by himself ... but not the progressbar !!!
      58             :     // it must be set explicitly
      59           0 :     m_xProgressBar->setVisible( true );
      60             :     // Reset to defaults !!!
      61             :     // (progressbar take automatically its own defaults)
      62           0 :     m_xText->setText( "" );
      63             : 
      64           0 :     --m_refCount;
      65           0 : }
      66             : 
      67           0 : StatusIndicator::~StatusIndicator() {}
      68             : 
      69             : //  XInterface
      70             : 
      71           0 : Any SAL_CALL StatusIndicator::queryInterface( const Type& rType ) throw( RuntimeException, std::exception )
      72             : {
      73             :     // Attention:
      74             :     //  Don't use mutex or guard in this method!!! Is a method of XInterface.
      75           0 :     Any aReturn;
      76           0 :     css::uno::Reference< XInterface > xDel = BaseContainerControl::impl_getDelegator();
      77           0 :     if ( xDel.is() )
      78             :     {
      79             :         // If an delegator exist, forward question to his queryInterface.
      80             :         // Delegator will ask his own queryAggregation!
      81           0 :         aReturn = xDel->queryInterface( rType );
      82             :     }
      83             :     else
      84             :     {
      85             :         // If an delegator unknown, forward question to own queryAggregation.
      86           0 :         aReturn = queryAggregation( rType );
      87             :     }
      88             : 
      89           0 :     return aReturn;
      90             : }
      91             : 
      92             : //  XInterface
      93             : 
      94           0 : void SAL_CALL StatusIndicator::acquire() throw()
      95             : {
      96             :     // Attention:
      97             :     //  Don't use mutex or guard in this method!!! Is a method of XInterface.
      98             : 
      99             :     // Forward to baseclass
     100           0 :     BaseControl::acquire();
     101           0 : }
     102             : 
     103             : //  XInterface
     104             : 
     105           0 : void SAL_CALL StatusIndicator::release() throw()
     106             : {
     107             :     // Attention:
     108             :     //  Don't use mutex or guard in this method!!! Is a method of XInterface.
     109             : 
     110             :     // Forward to baseclass
     111           0 :     BaseControl::release();
     112           0 : }
     113             : 
     114             : //  XTypeProvider
     115             : 
     116           0 : Sequence< Type > SAL_CALL StatusIndicator::getTypes() throw( RuntimeException, std::exception )
     117             : {
     118             :     // Optimize this method !
     119             :     // We initialize a static variable only one time. And we don't must use a mutex at every call!
     120             :     // For the first call; pTypeCollection is NULL - for the second call pTypeCollection is different from NULL!
     121             :     static OTypeCollection* pTypeCollection = NULL;
     122             : 
     123           0 :     if ( pTypeCollection == NULL )
     124             :     {
     125             :         // Ready for multithreading; get global mutex for first call of this method only! see before
     126           0 :         MutexGuard aGuard( Mutex::getGlobalMutex() );
     127             : 
     128             :         // Control these pointer again ... it can be, that another instance will be faster then these!
     129           0 :         if ( pTypeCollection == NULL )
     130             :         {
     131             :             // Create a static typecollection ...
     132           0 :             static OTypeCollection aTypeCollection  ( cppu::UnoType<XLayoutConstrains>::get(),
     133           0 :                                                       cppu::UnoType<XStatusIndicator>::get(),
     134             :                                                       BaseContainerControl::getTypes()
     135           0 :                                                     );
     136             :             // ... and set his address to static pointer!
     137           0 :             pTypeCollection = &aTypeCollection;
     138           0 :         }
     139             :     }
     140             : 
     141           0 :     return pTypeCollection->getTypes();
     142             : }
     143             : 
     144             : //  XAggregation
     145             : 
     146           0 : Any SAL_CALL StatusIndicator::queryAggregation( const Type& aType ) throw( RuntimeException, std::exception )
     147             : {
     148             :     // Ask for my own supported interfaces ...
     149             :     // Attention: XTypeProvider and XInterface are supported by OComponentHelper!
     150             :     Any aReturn ( ::cppu::queryInterface( aType                                     ,
     151             :                                           static_cast< XLayoutConstrains*   > ( this )  ,
     152             :                                           static_cast< XStatusIndicator*    > ( this )
     153             :                                         )
     154           0 :                 );
     155             : 
     156             :     // If searched interface not supported by this class ...
     157           0 :     if ( !aReturn.hasValue() )
     158             :     {
     159             :         // ... ask baseclasses.
     160           0 :         aReturn = BaseControl::queryAggregation( aType );
     161             :     }
     162             : 
     163           0 :     return aReturn;
     164             : }
     165             : 
     166             : //  XStatusIndicator
     167             : 
     168           0 : void SAL_CALL StatusIndicator::start( const OUString& sText, sal_Int32 nRange ) throw( RuntimeException, std::exception )
     169             : {
     170             :     // Ready for multithreading
     171           0 :     MutexGuard aGuard( m_aMutex );
     172             : 
     173             :     // Initialize status controls with given values.
     174           0 :     m_xText->setText( sText );
     175           0 :     m_xProgressBar->setRange( 0, nRange );
     176             :     // force repaint ... fixedtext has changed !
     177           0 :     impl_recalcLayout ( WindowEvent(static_cast< OWeakObject* >(this),0,0,impl_getWidth(),impl_getHeight(),0,0,0,0) );
     178           0 : }
     179             : 
     180             : //  XStatusIndicator
     181             : 
     182           0 : void SAL_CALL StatusIndicator::end() throw( RuntimeException, std::exception )
     183             : {
     184             :     // Ready for multithreading
     185           0 :     MutexGuard aGuard( m_aMutex );
     186             : 
     187             :     // Clear values of status controls.
     188           0 :     m_xText->setText( OUString() );
     189           0 :     m_xProgressBar->setValue( 0 );
     190           0 :     setVisible( false );
     191           0 : }
     192             : 
     193             : //  XStatusIndicator
     194             : 
     195           0 : void SAL_CALL StatusIndicator::setText( const OUString& sText ) throw( RuntimeException, std::exception )
     196             : {
     197             :     // Ready for multithreading
     198           0 :     MutexGuard aGuard( m_aMutex );
     199             : 
     200             :     // Take text on right control
     201           0 :     m_xText->setText( sText );
     202           0 : }
     203             : 
     204             : //  XStatusIndicator
     205             : 
     206           0 : void SAL_CALL StatusIndicator::setValue( sal_Int32 nValue ) throw( RuntimeException, std::exception )
     207             : {
     208             :     // Ready for multithreading
     209           0 :     MutexGuard aGuard( m_aMutex );
     210             : 
     211             :     // Take value on right control
     212           0 :     m_xProgressBar->setValue( nValue );
     213           0 : }
     214             : 
     215             : //  XStatusIndicator
     216             : 
     217           0 : void SAL_CALL StatusIndicator::reset() throw( RuntimeException, std::exception )
     218             : {
     219             :     // Ready for multithreading
     220           0 :     MutexGuard aGuard( m_aMutex );
     221             : 
     222             :     // Clear values of status controls.
     223             :     // (Don't hide the window! User will reset current values ... but he will not finish using of indicator!)
     224           0 :     m_xText->setText( OUString() );
     225           0 :     m_xProgressBar->setValue( 0 );
     226           0 : }
     227             : 
     228             : //  XLayoutConstrains
     229             : 
     230           0 : Size SAL_CALL StatusIndicator::getMinimumSize () throw( RuntimeException, std::exception )
     231             : {
     232           0 :     return Size (STATUSINDICATOR_DEFAULT_WIDTH, STATUSINDICATOR_DEFAULT_HEIGHT);
     233             : }
     234             : 
     235             : //  XLayoutConstrains
     236             : 
     237           0 : Size SAL_CALL StatusIndicator::getPreferredSize () throw( RuntimeException, std::exception )
     238             : {
     239             :     // Ready for multithreading
     240           0 :     ClearableMutexGuard aGuard ( m_aMutex );
     241             : 
     242             :     // get information about required place of child controls
     243           0 :     css::uno::Reference< XLayoutConstrains >  xTextLayout ( m_xText, UNO_QUERY );
     244           0 :     Size                            aTextSize   = xTextLayout->getPreferredSize();
     245             : 
     246           0 :     aGuard.clear ();
     247             : 
     248             :     // calc preferred size of status indicator
     249           0 :     sal_Int32 nWidth  = impl_getWidth();
     250           0 :     sal_Int32 nHeight = (2*STATUSINDICATOR_FREEBORDER)+aTextSize.Height;
     251             : 
     252             :     // norm to minimum
     253           0 :     if ( nWidth<STATUSINDICATOR_DEFAULT_WIDTH )
     254             :     {
     255           0 :         nWidth = STATUSINDICATOR_DEFAULT_WIDTH;
     256             :     }
     257           0 :     if ( nHeight<STATUSINDICATOR_DEFAULT_HEIGHT )
     258             :     {
     259           0 :         nHeight = STATUSINDICATOR_DEFAULT_HEIGHT;
     260             :     }
     261             : 
     262             :     // return to caller
     263           0 :     return Size ( nWidth, nHeight );
     264             : }
     265             : 
     266             : //  XLayoutConstrains
     267             : 
     268           0 : Size SAL_CALL StatusIndicator::calcAdjustedSize ( const Size& /*rNewSize*/ ) throw( RuntimeException, std::exception )
     269             : {
     270           0 :     return getPreferredSize ();
     271             : }
     272             : 
     273             : //  XControl
     274             : 
     275           0 : void SAL_CALL StatusIndicator::createPeer (
     276             :     const css::uno::Reference< XToolkit > & rToolkit,
     277             :     const css::uno::Reference< XWindowPeer > & rParent
     278             : ) throw( RuntimeException, std::exception )
     279             : {
     280           0 :     if( !getPeer().is() )
     281             :     {
     282           0 :         BaseContainerControl::createPeer( rToolkit, rParent );
     283             : 
     284             :         // If user forget to call "setPosSize()", we have still a correct size.
     285             :         // And a "MinimumSize" IS A "MinimumSize"!
     286             :         // We change not the position of control at this point.
     287           0 :         Size aDefaultSize = getMinimumSize ();
     288           0 :         setPosSize ( 0, 0, aDefaultSize.Width, aDefaultSize.Height, PosSize::SIZE );
     289             :     }
     290           0 : }
     291             : 
     292             : //  XControl
     293             : 
     294           0 : sal_Bool SAL_CALL StatusIndicator::setModel ( const css::uno::Reference< XControlModel > & /*rModel*/ ) throw( RuntimeException, std::exception )
     295             : {
     296             :     // We have no model.
     297           0 :     return false;
     298             : }
     299             : 
     300             : //  XControl
     301             : 
     302           0 : css::uno::Reference< XControlModel > SAL_CALL StatusIndicator::getModel () throw( RuntimeException, std::exception )
     303             : {
     304             :     // We have no model.
     305             :     // return (XControlModel*)this;
     306           0 :     return css::uno::Reference< XControlModel >  ();
     307             : }
     308             : 
     309             : //  XComponent
     310             : 
     311           0 : void SAL_CALL StatusIndicator::dispose () throw( RuntimeException, std::exception )
     312             : {
     313             :     // Ready for multithreading
     314           0 :     MutexGuard aGuard ( m_aMutex );
     315             : 
     316             :     // "removeControl()" control the state of a reference
     317           0 :     css::uno::Reference< XControl >  xTextControl     ( m_xText       , UNO_QUERY );
     318             : 
     319           0 :     removeControl( xTextControl     );
     320           0 :     removeControl( m_xProgressBar.get() );
     321             : 
     322             :     // do'nt use "...->clear ()" or "... = XFixedText ()"
     323             :     // when other hold a reference at this object !!!
     324           0 :     xTextControl->dispose();
     325           0 :     m_xProgressBar->dispose();
     326           0 :     BaseContainerControl::dispose();
     327           0 : }
     328             : 
     329             : //  XWindow
     330             : 
     331           0 : void SAL_CALL StatusIndicator::setPosSize (
     332             :     sal_Int32 nX,
     333             :     sal_Int32 nY,
     334             :     sal_Int32 nWidth,
     335             :     sal_Int32 nHeight,
     336             :     sal_Int16 nFlags
     337             : ) throw( RuntimeException, std::exception )
     338             : {
     339           0 :     Rectangle   aBasePosSize = getPosSize ();
     340           0 :     BaseContainerControl::setPosSize (nX, nY, nWidth, nHeight, nFlags);
     341             : 
     342             :     // if position or size changed
     343           0 :     if (
     344           0 :         ( nWidth  != aBasePosSize.Width ) ||
     345           0 :         ( nHeight != aBasePosSize.Height)
     346             :        )
     347             :     {
     348             :         // calc new layout for controls
     349           0 :         impl_recalcLayout ( WindowEvent(static_cast< OWeakObject* >(this),0,0,nWidth,nHeight,0,0,0,0) );
     350             :         // clear background (!)
     351             :         // [Children were repainted in "recalcLayout" by setPosSize() automatically!]
     352           0 :         getPeer()->invalidate(2);
     353             :         // and repaint the control
     354           0 :         impl_paint ( 0, 0, impl_getGraphicsPeer() );
     355             :     }
     356           0 : }
     357             : 
     358             : //  impl but public method to register service
     359             : 
     360           0 : const Sequence< OUString > StatusIndicator::impl_getStaticSupportedServiceNames()
     361             : {
     362           0 :     return css::uno::Sequence<OUString>();
     363             : }
     364             : 
     365             : //  impl but public method to register service
     366             : 
     367           0 : const OUString StatusIndicator::impl_getStaticImplementationName()
     368             : {
     369           0 :     return OUString("stardiv.UnoControls.StatusIndicator");
     370             : }
     371             : 
     372             : //  protected method
     373             : 
     374           0 : WindowDescriptor* StatusIndicator::impl_getWindowDescriptor( const css::uno::Reference< XWindowPeer >& xParentPeer )
     375             : {
     376             :     // - used from "createPeer()" to set the values of an ::com::sun::star::awt::WindowDescriptor !!!
     377             :     // - if you will change the descriptor-values, you must override this virtuell function
     378             :     // - the caller must release the memory for this dynamical descriptor !!!
     379             : 
     380           0 :     WindowDescriptor* pDescriptor = new WindowDescriptor;
     381             : 
     382           0 :     pDescriptor->Type               =   WindowClass_SIMPLE;
     383           0 :     pDescriptor->WindowServiceName  =   "floatingwindow";
     384           0 :     pDescriptor->ParentIndex        =   -1;
     385           0 :     pDescriptor->Parent             =   xParentPeer;
     386           0 :     pDescriptor->Bounds             =   getPosSize ();
     387             : 
     388           0 :     return pDescriptor;
     389             : }
     390             : 
     391             : //  protected method
     392             : 
     393           0 : void StatusIndicator::impl_paint ( sal_Int32 nX, sal_Int32 nY, const css::uno::Reference< XGraphics > & rGraphics )
     394             : {
     395             :     // This paint method ist not buffered !!
     396             :     // Every request paint the completely control. ( but only, if peer exist )
     397           0 :      if ( rGraphics.is () )
     398             :     {
     399           0 :         MutexGuard  aGuard (m_aMutex);
     400             : 
     401             :         // background = gray
     402           0 :         css::uno::Reference< XWindowPeer > xPeer( impl_getPeerWindow(), UNO_QUERY );
     403           0 :         if( xPeer.is() )
     404           0 :             xPeer->setBackground( STATUSINDICATOR_BACKGROUNDCOLOR );
     405             : 
     406             :         // FixedText background = gray
     407           0 :         css::uno::Reference< XControl > xTextControl( m_xText, UNO_QUERY );
     408           0 :         xPeer = xTextControl->getPeer();
     409           0 :         if( xPeer.is() )
     410           0 :             xPeer->setBackground( STATUSINDICATOR_BACKGROUNDCOLOR );
     411             : 
     412             :         // Progress background = gray
     413           0 :         xPeer = m_xProgressBar->getPeer();
     414           0 :         if( xPeer.is() )
     415           0 :             xPeer->setBackground( STATUSINDICATOR_BACKGROUNDCOLOR );
     416             : 
     417             :         // paint shadow border
     418           0 :         rGraphics->setLineColor ( STATUSINDICATOR_LINECOLOR_BRIGHT                          );
     419           0 :         rGraphics->drawLine     ( nX, nY, impl_getWidth(), nY               );
     420           0 :         rGraphics->drawLine     ( nX, nY, nX             , impl_getHeight() );
     421             : 
     422           0 :         rGraphics->setLineColor ( STATUSINDICATOR_LINECOLOR_SHADOW                                                              );
     423           0 :         rGraphics->drawLine     ( impl_getWidth()-1, impl_getHeight()-1, impl_getWidth()-1, nY                  );
     424           0 :         rGraphics->drawLine     ( impl_getWidth()-1, impl_getHeight()-1, nX               , impl_getHeight()-1  );
     425             :     }
     426           0 : }
     427             : 
     428             : //  protected method
     429             : 
     430           0 : void StatusIndicator::impl_recalcLayout ( const WindowEvent& aEvent )
     431             : {
     432             :     sal_Int32   nX_ProgressBar;
     433             :     sal_Int32   nY_ProgressBar;
     434             :     sal_Int32   nWidth_ProgressBar;
     435             :     sal_Int32   nHeight_ProgressBar;
     436             :     sal_Int32   nX_Text;
     437             :     sal_Int32   nY_Text;
     438             :     sal_Int32   nWidth_Text;
     439             :     sal_Int32   nHeight_Text;
     440             : 
     441             :     // Ready for multithreading
     442           0 :     MutexGuard aGuard ( m_aMutex );
     443             : 
     444             :     // get information about required place of child controls
     445           0 :     Size                            aWindowSize     ( aEvent.Width, aEvent.Height );
     446           0 :     css::uno::Reference< XLayoutConstrains >  xTextLayout     ( m_xText, UNO_QUERY );
     447           0 :     Size                            aTextSize       = xTextLayout->getPreferredSize();
     448             : 
     449           0 :     if( aWindowSize.Width < STATUSINDICATOR_DEFAULT_WIDTH )
     450             :     {
     451           0 :         aWindowSize.Width = STATUSINDICATOR_DEFAULT_WIDTH;
     452             :     }
     453           0 :     if( aWindowSize.Height < STATUSINDICATOR_DEFAULT_HEIGHT )
     454             :     {
     455           0 :         aWindowSize.Height = STATUSINDICATOR_DEFAULT_HEIGHT;
     456             :     }
     457             : 
     458             :     // calc position and size of child controls
     459           0 :     nX_Text             = STATUSINDICATOR_FREEBORDER;
     460           0 :     nY_Text             = STATUSINDICATOR_FREEBORDER;
     461           0 :     nWidth_Text         = aTextSize.Width;
     462           0 :     nHeight_Text        = aTextSize.Height;
     463             : 
     464           0 :     nX_ProgressBar      = nX_Text+nWidth_Text+STATUSINDICATOR_FREEBORDER;
     465           0 :     nY_ProgressBar      = nY_Text;
     466           0 :     nWidth_ProgressBar  = aWindowSize.Width-nWidth_Text-(3*STATUSINDICATOR_FREEBORDER);
     467           0 :     nHeight_ProgressBar = nHeight_Text;
     468             : 
     469             :     // Set new position and size on all controls
     470           0 :     css::uno::Reference< XWindow >  xTextWindow       ( m_xText       , UNO_QUERY );
     471             : 
     472           0 :     xTextWindow->setPosSize     ( nX_Text       , nY_Text       , nWidth_Text       , nHeight_Text          , 15 );
     473           0 :     m_xProgressBar->setPosSize( nX_ProgressBar, nY_ProgressBar, nWidth_ProgressBar, nHeight_ProgressBar, 15 );
     474           0 : }
     475             : 
     476             : }   // namespace unocontrols
     477             : 
     478             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11