/************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * Copyright 2008 by Sun Microsystems, Inc. * * OpenOffice.org - a multi-platform office productivity suite * * $RCSfile: layoutmanager.hxx,v $ * $Revision: 1.34 $ * * This file is part of OpenOffice.org. * * OpenOffice.org is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License version 3 * only, as published by the Free Software Foundation. * * OpenOffice.org is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License version 3 for more details * (a copy is included in the LICENSE file that accompanied this code). * * You should have received a copy of the GNU Lesser General Public License * version 3 along with OpenOffice.org. If not, see * * for a copy of the LGPLv3 License. * ************************************************************************/ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_framework.hxx" //_________________________________________________________________________________________________________________ // my own includes //_________________________________________________________________________________________________________________ #include "helpers.hxx" #include #include //_________________________________________________________________________________________________________________ // interface includes //_________________________________________________________________________________________________________________ #include #include #include #include #include #include //_________________________________________________________________________________________________________________ // other includes //_________________________________________________________________________________________________________________ #include #include #include #include #include //_________________________________________________________________________________________________________________ // namespace //_________________________________________________________________________________________________________________ using namespace com::sun::star; namespace framework { // ATTENTION! // This value is directly copied from the sfx2 project. // You have to change BOTH values, see sfx2/inc/sfx2/sfxsids.hrc (SID_DOCKWIN_START) static const sal_Int32 DOCKWIN_ID_BASE = 9800; bool lcl_checkUIElement(const uno::Reference< ui::XUIElement >& xUIElement, awt::Rectangle& _rPosSize, uno::Reference< awt::XWindow >& _xWindow) { bool bRet = xUIElement.is(); if ( bRet ) { vos::OGuard aGuard( Application::GetSolarMutex() ); _xWindow.set( xUIElement->getRealInterface(), uno::UNO_QUERY ); _rPosSize = _xWindow->getPosSize(); Window* pWindow = VCLUnoHelper::GetWindow( _xWindow ); if ( pWindow->GetType() == WINDOW_TOOLBOX ) { ::Size aSize = ((ToolBox*)pWindow)->CalcWindowSizePixel( 1 ); _rPosSize.Width = aSize.Width(); _rPosSize.Height = aSize.Height(); } } // if ( xUIElement.is() ) return bRet; } uno::Reference< awt::XWindowPeer > createToolkitWindow( const uno::Reference< lang::XMultiServiceFactory >& rFactory, const uno::Reference< awt::XWindowPeer >& rParent, const char* pService ) { const rtl::OUString aAWTToolkit( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.Toolkit" )); uno::Reference< awt::XWindowPeer > xPeer; if ( rFactory.is() ) { uno::Reference< awt::XToolkit > xToolkit( rFactory->createInstance( aAWTToolkit ), uno::UNO_QUERY_THROW ); if ( xToolkit.is() ) { // describe window properties. css::awt::WindowDescriptor aDescriptor; aDescriptor.Type = awt::WindowClass_SIMPLE ; aDescriptor.WindowServiceName = DECLARE_ASCII(pService) ; aDescriptor.ParentIndex = -1 ; aDescriptor.Parent = uno::Reference< awt::XWindowPeer >( rParent, uno::UNO_QUERY ) ; aDescriptor.Bounds = awt::Rectangle(0,0,0,0) ; aDescriptor.WindowAttributes = 0 ; // create a awt window xPeer = xToolkit->createWindow( aDescriptor ); } } return xPeer; } // convert alignment constant to vcl's WindowAlign type WindowAlign ImplConvertAlignment( sal_Int16 aAlignment ) { if ( aAlignment == ui::DockingArea_DOCKINGAREA_LEFT ) return WINDOWALIGN_LEFT; else if ( aAlignment == ui::DockingArea_DOCKINGAREA_RIGHT ) return WINDOWALIGN_RIGHT; else if ( aAlignment == ui::DockingArea_DOCKINGAREA_TOP ) return WINDOWALIGN_TOP; else return WINDOWALIGN_BOTTOM; } bool impl_parseResourceURL( const rtl::OUString aResourceURL, rtl::OUString& aElementType, rtl::OUString& aElementName ) { sal_Int32 nIndex = 0; ::rtl::OUString aUIResourceURL( UIRESOURCE_URL ); if ( aResourceURL.indexOf( aUIResourceURL ) == 0 ) { ::rtl::OUString aPathPart = aResourceURL.copy( aUIResourceURL.getLength() ); ::rtl::OUString aUIResource = aPathPart.getToken( 0, (sal_Unicode)'/', nIndex ); aElementType = aPathPart.getToken( 0, (sal_Unicode)'/', nIndex ); aElementName = aPathPart.getToken( 0, (sal_Unicode)'/', nIndex ); return true; } return false; } css::awt::Rectangle impl_convertRectangleToAWT( const ::Rectangle& rRect ) { css::awt::Rectangle aRect; aRect.X = rRect.Left(); aRect.Y = rRect.Top(); aRect.Width = rRect.GetWidth(); aRect.Height = rRect.GetHeight(); return aRect; } ::Rectangle impl_convertAWTToRectangle( const ::com::sun::star::awt::Rectangle& rRect ) { ::Rectangle aRect; aRect.Left() = rRect.X; aRect.Top() = rRect.Y; aRect.Right() = rRect.X + rRect.Width; aRect.Bottom() = rRect.Y + rRect.Height; return aRect; } uno::Reference< frame::XModel > impl_getModelFromFrame( const uno::Reference< frame::XFrame >& rFrame ) { // Query for the model to get check the context information uno::Reference< frame::XModel > xModel; if ( rFrame.is() ) { uno::Reference< frame::XController > xController( rFrame->getController(), uno::UNO_QUERY ); if ( xController.is() ) xModel = xController->getModel(); } return xModel; } sal_Bool implts_isPreviewModel( const uno::Reference< frame::XModel >& xModel ) { if ( xModel.is() ) { ::comphelper::MediaDescriptor aDesc( xModel->getArgs() ); return aDesc.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_PREVIEW(), (sal_Bool)sal_False); } else return sal_False; } sal_Bool implts_isFrameOrWindowTop( const uno::Reference< frame::XFrame >& xFrame ) { if (xFrame->isTop()) return sal_True; uno::Reference< awt::XTopWindow > xWindowCheck(xFrame->getContainerWindow(), uno::UNO_QUERY); // dont use _THROW here ... its a check only if (xWindowCheck.is()) { // --> PB 2007-06-18 #i76867# top and system window is required. ::vos::OGuard aSolarLock(&Application::GetSolarMutex()); uno::Reference< awt::XWindow > xWindow( xWindowCheck, uno::UNO_QUERY ); Window* pWindow = VCLUnoHelper::GetWindow( xWindow ); return ( pWindow && pWindow->IsSystemWindow() ); // <-- } return sal_False; } void impl_setDockingWindowVisibility( const css::uno::Reference< css::lang::XMultiServiceFactory>& rSMGR, const css::uno::Reference< css::frame::XFrame >& rFrame, const ::rtl::OUString& rDockingWindowName, bool bVisible ) { const ::rtl::OUString aDockWinPrefixCommand( RTL_CONSTASCII_USTRINGPARAM( "DockingWindow" )); css::uno::WeakReference< css::frame::XDispatchHelper > xDispatchHelper; sal_Int32 nID = rDockingWindowName.toInt32(); sal_Int32 nIndex = nID - DOCKWIN_ID_BASE; css::uno::Reference< css::frame::XDispatchProvider > xProvider(rFrame, css::uno::UNO_QUERY); if ( nIndex >= 0 && xProvider.is() ) { ::rtl::OUString aDockWinCommand( RTL_CONSTASCII_USTRINGPARAM( ".uno:" )); ::rtl::OUString aDockWinArgName( aDockWinPrefixCommand ); aDockWinArgName += ::rtl::OUString::valueOf( nIndex ); css::uno::Sequence< css::beans::PropertyValue > aArgs(1); aArgs[0].Name = aDockWinArgName; aArgs[0].Value = css::uno::makeAny( bVisible ); css::uno::Reference< css::frame::XDispatchHelper > xDispatcher( xDispatchHelper ); if ( !xDispatcher.is()) { xDispatcher = css::uno::Reference< css::frame::XDispatchHelper >( rSMGR->createInstance(SERVICENAME_DISPATCHHELPER), css::uno::UNO_QUERY_THROW); } aDockWinCommand = aDockWinCommand + aDockWinArgName; xDispatcher->executeDispatch( xProvider, aDockWinCommand, ::rtl::OUString::createFromAscii("_self"), 0, aArgs); } } void impl_addWindowListeners( const css::uno::Reference< css::uno::XInterface >& xThis, const css::uno::Reference< css::ui::XUIElement >& xUIElement ) { css::uno::Reference< css::awt::XWindow > xWindow( xUIElement->getRealInterface(), css::uno::UNO_QUERY ); css::uno::Reference< css::awt::XDockableWindow > xDockWindow( xUIElement->getRealInterface(), css::uno::UNO_QUERY ); if ( xDockWindow.is() && xWindow.is() ) { try { xDockWindow->addDockableWindowListener( css::uno::Reference< css::awt::XDockableWindowListener >( xThis, css::uno::UNO_QUERY )); xWindow->addWindowListener( css::uno::Reference< css::awt::XWindowListener >( xThis, css::uno::UNO_QUERY )); xDockWindow->enableDocking( sal_True ); } catch ( css::uno::Exception& ) { } } } css::uno::Reference< css::awt::XWindowPeer > implts_createToolkitWindow( const css::uno::Reference< css::awt::XToolkit >& rToolkit, const css::uno::Reference< css::awt::XWindowPeer >& rParent ) { css::uno::Reference< css::awt::XWindowPeer > xPeer; if ( rToolkit.is() ) { // describe window properties. css::awt::WindowDescriptor aDescriptor; aDescriptor.Type = css::awt::WindowClass_SIMPLE; aDescriptor.WindowServiceName = DECLARE_ASCII("dockingarea"); aDescriptor.ParentIndex = -1; aDescriptor.Parent = css::uno::Reference< css::awt::XWindowPeer >( rParent, css::uno::UNO_QUERY ); aDescriptor.Bounds = css::awt::Rectangle(0,0,0,0); aDescriptor.WindowAttributes = 0; // create a docking area window xPeer = rToolkit->createWindow( aDescriptor ); } return xPeer; } } // namespace framework