LCOV - code coverage report
Current view: top level - framework/source/layoutmanager - helpers.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 176 0.0 %
Date: 2014-04-14 Functions: 0 25 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 "helpers.hxx"
      21             : #include <services.h>
      22             : 
      23             : #include <com/sun/star/ui/DockingArea.hpp>
      24             : #include <com/sun/star/awt/Toolkit.hpp>
      25             : #include <com/sun/star/awt/XTopWindow.hpp>
      26             : #include <com/sun/star/frame/DispatchHelper.hpp>
      27             : #include <com/sun/star/awt/XDockableWindow.hpp>
      28             : #include <com/sun/star/awt/XDockableWindowListener.hpp>
      29             : #include <com/sun/star/awt/XWindowListener.hpp>
      30             : #include <com/sun/star/ui/XUIElement.hpp>
      31             : 
      32             : #include <comphelper/processfactory.hxx>
      33             : #include <unotools/mediadescriptor.hxx>
      34             : #include <vcl/svapp.hxx>
      35             : #include <toolkit/helper/vclunohelper.hxx>
      36             : 
      37             : using namespace com::sun::star;
      38             : 
      39             : namespace framework
      40             : {
      41             : 
      42           0 : bool hasEmptySize( const ::com::sun::star::awt::Size& rSize )
      43             : {
      44           0 :     return ( rSize.Width == 0 ) && ( rSize.Height == 0 );
      45             : }
      46             : 
      47           0 : bool hasDefaultPosValue( const ::com::sun::star::awt::Point& rPos )
      48             : {
      49           0 :     return (( rPos.X == SAL_MAX_INT32 ) || ( rPos.Y == SAL_MAX_INT32 ));
      50             : }
      51             : 
      52           0 : bool isDefaultPos( const ::com::sun::star::awt::Point& rPos )
      53             : {
      54           0 :     return (( rPos.X == SAL_MAX_INT32 ) && ( rPos.Y == SAL_MAX_INT32 ));
      55             : }
      56             : 
      57           0 : bool isReverseOrderDockingArea( const sal_Int32 nDockArea )
      58             : {
      59           0 :     ui::DockingArea eDockArea = static_cast< ui::DockingArea >( nDockArea );
      60           0 :     return (( eDockArea == ui::DockingArea_DOCKINGAREA_BOTTOM ) ||
      61           0 :             ( eDockArea == ui::DockingArea_DOCKINGAREA_RIGHT ));
      62             : }
      63             : 
      64           0 : bool isToolboxHorizontalAligned( ToolBox* pToolBox )
      65             : {
      66           0 :     if ( pToolBox )
      67           0 :         return (( pToolBox->GetAlign() == WINDOWALIGN_TOP ) || ( pToolBox->GetAlign() == WINDOWALIGN_BOTTOM ));
      68           0 :     return false;
      69             : }
      70             : 
      71           0 : bool isHorizontalDockingArea( const ui::DockingArea& nDockingArea )
      72             : {
      73           0 :     return (( nDockingArea == ui::DockingArea_DOCKINGAREA_TOP ) ||
      74           0 :             ( nDockingArea == ui::DockingArea_DOCKINGAREA_BOTTOM ));
      75             : }
      76             : 
      77           0 : bool isHorizontalDockingArea( const sal_Int32 nDockArea )
      78             : {
      79           0 :   return isHorizontalDockingArea(static_cast< ui::DockingArea >( nDockArea ));
      80             : }
      81             : 
      82           0 : OUString retrieveToolbarNameFromHelpURL( Window* pWindow )
      83             : {
      84           0 :     OUString aToolbarName;
      85             : 
      86           0 :     if ( pWindow->GetType() == WINDOW_TOOLBOX )
      87             :     {
      88           0 :         ToolBox* pToolBox = dynamic_cast<ToolBox *>( pWindow );
      89           0 :         if ( pToolBox )
      90             :         {
      91           0 :             aToolbarName = OStringToOUString( pToolBox->GetHelpId(), RTL_TEXTENCODING_UTF8 );
      92           0 :             sal_Int32 i = aToolbarName.lastIndexOf( ':' );
      93           0 :             if ( !aToolbarName.isEmpty() && ( i > 0 ) && (( i + 1 ) < aToolbarName.getLength() ))
      94           0 :                 aToolbarName = aToolbarName.copy( i+1 ); // Remove ".HelpId:" protocol from toolbar name
      95             :             else
      96           0 :               aToolbarName = OUString();
      97             :         }
      98             :     }
      99           0 :     return aToolbarName;
     100             : }
     101             : 
     102           0 : ToolBox* getToolboxPtr( Window* pWindow )
     103             : {
     104           0 :     ToolBox* pToolbox(NULL);
     105           0 :     if ( pWindow->GetType() == WINDOW_TOOLBOX )
     106           0 :         pToolbox = dynamic_cast<ToolBox*>( pWindow );
     107           0 :     return pToolbox;
     108             : }
     109             : 
     110           0 : Window* getWindowFromXUIElement( const uno::Reference< ui::XUIElement >& xUIElement )
     111             : {
     112           0 :     SolarMutexGuard aGuard;
     113           0 :     uno::Reference< awt::XWindow > xWindow;
     114           0 :     if ( xUIElement.is() )
     115           0 :         xWindow = uno::Reference< awt::XWindow >( xUIElement->getRealInterface(), uno::UNO_QUERY );
     116           0 :     return VCLUnoHelper::GetWindow( xWindow );
     117             : }
     118             : 
     119           0 : SystemWindow* getTopSystemWindow( const uno::Reference< awt::XWindow >& xWindow )
     120             : {
     121           0 :     Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
     122           0 :     while ( pWindow && !pWindow->IsSystemWindow() )
     123           0 :         pWindow = pWindow->GetParent();
     124             : 
     125           0 :     if ( pWindow )
     126           0 :         return (SystemWindow *)pWindow;
     127             :     else
     128           0 :         return 0;
     129             : }
     130             : 
     131           0 : void setZeroRectangle( ::Rectangle& rRect )
     132             : {
     133           0 :     rRect.setX(0);
     134           0 :     rRect.setY(0);
     135           0 :     rRect.setWidth(0);
     136           0 :     rRect.setHeight(0);
     137           0 : }
     138             : 
     139             : // ATTENTION!
     140             : // This value is directly copied from the sfx2 project.
     141             : // You have to change BOTH values, see sfx2/inc/sfx2/sfxsids.hrc (SID_DOCKWIN_START)
     142             : static const sal_Int32 DOCKWIN_ID_BASE = 9800;
     143             : 
     144           0 : bool lcl_checkUIElement(const uno::Reference< ui::XUIElement >& xUIElement, awt::Rectangle& _rPosSize, uno::Reference< awt::XWindow >& _xWindow)
     145             : {
     146           0 :     bool bRet = xUIElement.is();
     147           0 :     if ( bRet )
     148             :     {
     149           0 :         SolarMutexGuard aGuard;
     150           0 :         _xWindow.set( xUIElement->getRealInterface(), uno::UNO_QUERY );
     151           0 :         _rPosSize = _xWindow->getPosSize();
     152             : 
     153           0 :         Window* pWindow = VCLUnoHelper::GetWindow( _xWindow );
     154           0 :         if ( pWindow->GetType() == WINDOW_TOOLBOX )
     155             :         {
     156           0 :             ::Size aSize = ((ToolBox*)pWindow)->CalcWindowSizePixel( 1 );
     157           0 :             _rPosSize.Width = aSize.Width();
     158           0 :             _rPosSize.Height = aSize.Height();
     159           0 :         }
     160             :     } // if ( xUIElement.is() )
     161           0 :     return bRet;
     162             : }
     163             : 
     164           0 : uno::Reference< awt::XWindowPeer > createToolkitWindow( const uno::Reference< uno::XComponentContext >& rxContext, const uno::Reference< awt::XWindowPeer >& rParent, const char* pService )
     165             : {
     166           0 :     uno::Reference< awt::XToolkit2 > xToolkit = awt::Toolkit::create( rxContext );
     167             : 
     168             :     // describe window properties.
     169           0 :     css::awt::WindowDescriptor aDescriptor;
     170           0 :     aDescriptor.Type                =   awt::WindowClass_SIMPLE;
     171           0 :     aDescriptor.WindowServiceName   =   OUString::createFromAscii( pService );
     172           0 :     aDescriptor.ParentIndex         =   -1;
     173           0 :     aDescriptor.Parent              =   uno::Reference< awt::XWindowPeer >( rParent, uno::UNO_QUERY );
     174           0 :     aDescriptor.Bounds              =   awt::Rectangle(0,0,0,0);
     175           0 :     aDescriptor.WindowAttributes    =   0;
     176             : 
     177             :     // create a awt window
     178           0 :     uno::Reference< awt::XWindowPeer > xPeer = xToolkit->createWindow( aDescriptor );
     179             : 
     180           0 :     return xPeer;
     181             : }
     182             : 
     183             : // convert alignment constant to vcl's WindowAlign type
     184           0 : WindowAlign ImplConvertAlignment( sal_Int16 aAlignment )
     185             : {
     186           0 :     if ( aAlignment == ui::DockingArea_DOCKINGAREA_LEFT )
     187           0 :         return WINDOWALIGN_LEFT;
     188           0 :     else if ( aAlignment == ui::DockingArea_DOCKINGAREA_RIGHT )
     189           0 :         return WINDOWALIGN_RIGHT;
     190           0 :     else if ( aAlignment == ui::DockingArea_DOCKINGAREA_TOP )
     191           0 :         return WINDOWALIGN_TOP;
     192             :     else
     193           0 :         return WINDOWALIGN_BOTTOM;
     194             : }
     195             : 
     196           0 : OUString getElementTypeFromResourceURL( const OUString& aResourceURL )
     197             : {
     198           0 :     OUString aType;
     199             : 
     200           0 :     OUString aUIResourceURL( UIRESOURCE_URL );
     201           0 :     if ( aResourceURL.startsWith( aUIResourceURL ) )
     202             :     {
     203           0 :         sal_Int32       nIndex = 0;
     204           0 :         OUString aPathPart   = aResourceURL.copy( aUIResourceURL.getLength() );
     205           0 :         aPathPart.getToken( 0, (sal_Unicode)'/', nIndex );
     206             : 
     207           0 :         return aPathPart.getToken( 0, (sal_Unicode)'/', nIndex );
     208             :     }
     209             : 
     210           0 :     return aType;
     211             : }
     212             : 
     213           0 : void parseResourceURL( const OUString& aResourceURL, OUString& aElementType, OUString& aElementName )
     214             : {
     215           0 :     OUString aUIResourceURL( UIRESOURCE_URL );
     216           0 :     if ( aResourceURL.startsWith( aUIResourceURL ) )
     217             :     {
     218           0 :         sal_Int32       nIndex = 0;
     219           0 :         OUString aPathPart   = aResourceURL.copy( aUIResourceURL.getLength() );
     220           0 :         aPathPart.getToken( 0, (sal_Unicode)'/', nIndex );
     221             : 
     222           0 :         aElementType = aPathPart.getToken( 0, (sal_Unicode)'/', nIndex );
     223           0 :         aElementName = aPathPart.getToken( 0, (sal_Unicode)'/', nIndex );
     224           0 :     }
     225           0 : }
     226             : 
     227           0 : ::com::sun::star::awt::Rectangle putRectangleValueToAWT( const ::Rectangle& rRect )
     228             : {
     229           0 :     css::awt::Rectangle aRect;
     230           0 :     aRect.X = rRect.Left();
     231           0 :     aRect.Y = rRect.Top();
     232           0 :     aRect.Width = rRect.Right();
     233           0 :     aRect.Height = rRect.Bottom();
     234             : 
     235           0 :     return aRect;
     236             : }
     237             : 
     238           0 : ::Rectangle putAWTToRectangle( const ::com::sun::star::awt::Rectangle& rRect )
     239             : {
     240           0 :     ::Rectangle aRect;
     241           0 :     aRect.Left() = rRect.X;
     242           0 :     aRect.Top() = rRect.Y;
     243           0 :     aRect.Right() = rRect.Width;
     244           0 :     aRect.Bottom() = rRect.Height;
     245             : 
     246           0 :     return aRect;
     247             : }
     248             : 
     249           0 : bool equalRectangles( const css::awt::Rectangle& rRect1,
     250             :                       const css::awt::Rectangle& rRect2 )
     251             : {
     252           0 :     return (( rRect1.X == rRect2.X ) &&
     253           0 :             ( rRect1.Y == rRect2.Y ) &&
     254           0 :             ( rRect1.Width == rRect2.Width ) &&
     255           0 :             ( rRect1.Height == rRect2.Height ));
     256             : }
     257             : 
     258           0 : uno::Reference< frame::XModel > impl_getModelFromFrame( const uno::Reference< frame::XFrame >& rFrame )
     259             : {
     260             :     // Query for the model to get check the context information
     261           0 :     uno::Reference< frame::XModel > xModel;
     262           0 :         if ( rFrame.is() )
     263             :         {
     264           0 :         uno::Reference< frame::XController > xController( rFrame->getController(), uno::UNO_QUERY );
     265           0 :             if ( xController.is() )
     266           0 :                 xModel = xController->getModel();
     267             :         }
     268             : 
     269           0 :     return xModel;
     270             : }
     271             : 
     272           0 : bool implts_isPreviewModel( const uno::Reference< frame::XModel >& xModel )
     273             : {
     274           0 :     if ( xModel.is() )
     275             :     {
     276           0 :         utl::MediaDescriptor aDesc( xModel->getArgs() );
     277           0 :         return aDesc.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_PREVIEW(), sal_False);
     278             :     }
     279             :     else
     280           0 :         return false;
     281             : }
     282             : 
     283           0 : bool implts_isFrameOrWindowTop( const uno::Reference< frame::XFrame >& xFrame )
     284             : {
     285           0 :     if (xFrame->isTop())
     286           0 :         return true;
     287             : 
     288           0 :     uno::Reference< awt::XTopWindow > xWindowCheck(xFrame->getContainerWindow(), uno::UNO_QUERY); // dont use _THROW here ... it's a check only
     289           0 :     if (xWindowCheck.is())
     290             :     {
     291             :         // #i76867# top and system window is required.
     292           0 :         SolarMutexGuard aGuard;
     293           0 :         uno::Reference< awt::XWindow > xWindow( xWindowCheck, uno::UNO_QUERY );
     294           0 :         Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
     295           0 :         return ( pWindow && pWindow->IsSystemWindow() );
     296             :     }
     297             : 
     298           0 :     return false;
     299             : }
     300             : 
     301           0 : void impl_setDockingWindowVisibility( const css::uno::Reference< css::uno::XComponentContext>& rxContext, const css::uno::Reference< css::frame::XFrame >& rFrame, const OUString& rDockingWindowName, bool bVisible )
     302             : {
     303           0 :     const OUString aDockWinPrefixCommand( "DockingWindow" );
     304             : 
     305           0 :     sal_Int32 nID    = rDockingWindowName.toInt32();
     306           0 :     sal_Int32 nIndex = nID - DOCKWIN_ID_BASE;
     307             : 
     308           0 :     css::uno::Reference< css::frame::XDispatchProvider > xProvider(rFrame, css::uno::UNO_QUERY);
     309           0 :     if ( nIndex >= 0 && xProvider.is() )
     310             :     {
     311           0 :         OUString aDockWinCommand( ".uno:" );
     312           0 :         OUString aDockWinArgName( aDockWinPrefixCommand );
     313             : 
     314           0 :         aDockWinArgName += OUString::number( nIndex );
     315             : 
     316           0 :         css::uno::Sequence< css::beans::PropertyValue > aArgs(1);
     317           0 :         aArgs[0].Name  = aDockWinArgName;
     318           0 :         aArgs[0].Value = css::uno::makeAny( bVisible );
     319             : 
     320           0 :         css::uno::Reference< css::frame::XDispatchHelper > xDispatcher = css::frame::DispatchHelper::create( rxContext );
     321             : 
     322           0 :         aDockWinCommand = aDockWinCommand + aDockWinArgName;
     323           0 :         xDispatcher->executeDispatch(
     324             :             xProvider,
     325             :             aDockWinCommand,
     326             :             OUString("_self"),
     327             :             0,
     328           0 :             aArgs);
     329           0 :     }
     330           0 : }
     331             : 
     332           0 : void impl_addWindowListeners(
     333             :     const css::uno::Reference< css::uno::XInterface >& xThis,
     334             :     const css::uno::Reference< css::ui::XUIElement >& xUIElement )
     335             : {
     336           0 :     css::uno::Reference< css::awt::XWindow > xWindow( xUIElement->getRealInterface(), css::uno::UNO_QUERY );
     337           0 :     css::uno::Reference< css::awt::XDockableWindow > xDockWindow( xUIElement->getRealInterface(), css::uno::UNO_QUERY );
     338           0 :     if ( xDockWindow.is() && xWindow.is() )
     339             :     {
     340             :         try
     341             :         {
     342           0 :             xDockWindow->addDockableWindowListener(
     343             :                 css::uno::Reference< css::awt::XDockableWindowListener >(
     344           0 :                     xThis, css::uno::UNO_QUERY ));
     345           0 :             xWindow->addWindowListener(
     346             :                 css::uno::Reference< css::awt::XWindowListener >(
     347           0 :                     xThis, css::uno::UNO_QUERY ));
     348           0 :             xDockWindow->enableDocking( sal_True );
     349             :         }
     350           0 :         catch ( const css::uno::Exception& )
     351             :         {
     352             :         }
     353           0 :     }
     354           0 : }
     355             : 
     356             : } // namespace framework
     357             : 
     358             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10