16d739b60SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
36d739b60SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
46d739b60SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
56d739b60SAndrew Rist  * distributed with this work for additional information
66d739b60SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
76d739b60SAndrew Rist  * to you under the Apache License, Version 2.0 (the
86d739b60SAndrew Rist  * "License"); you may not use this file except in compliance
96d739b60SAndrew Rist  * with the License.  You may obtain a copy of the License at
106d739b60SAndrew Rist  *
116d739b60SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
126d739b60SAndrew Rist  *
136d739b60SAndrew Rist  * Unless required by applicable law or agreed to in writing,
146d739b60SAndrew Rist  * software distributed under the License is distributed on an
156d739b60SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
166d739b60SAndrew Rist  * KIND, either express or implied.  See the License for the
176d739b60SAndrew Rist  * specific language governing permissions and limitations
186d739b60SAndrew Rist  * under the License.
196d739b60SAndrew Rist  *
206d739b60SAndrew Rist  *************************************************************/
216d739b60SAndrew Rist 
226d739b60SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_framework.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir // my own includes
28cdf0e10cSrcweir #include "helpers.hxx"
29cdf0e10cSrcweir #include <threadhelp/resetableguard.hxx>
30cdf0e10cSrcweir #include <services.h>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir // interface includes
33cdf0e10cSrcweir #include <com/sun/star/ui/DockingArea.hpp>
34cdf0e10cSrcweir #include <com/sun/star/awt/XTopWindow.hpp>
35cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchHelper.hpp>
36cdf0e10cSrcweir #include <com/sun/star/awt/XDockableWindow.hpp>
37cdf0e10cSrcweir #include <com/sun/star/awt/XDockableWindowListener.hpp>
38cdf0e10cSrcweir #include <com/sun/star/awt/XWindowListener.hpp>
39cdf0e10cSrcweir #include <com/sun/star/ui/XUIElement.hpp>
40cdf0e10cSrcweir 
41cdf0e10cSrcweir // other includes
42cdf0e10cSrcweir #include <comphelper/mediadescriptor.hxx>
43cdf0e10cSrcweir #include <vcl/svapp.hxx>
44cdf0e10cSrcweir #include <vos/mutex.hxx>
45*b63233d8Sdamjan #include <toolkit/helper/vclunohelper.hxx>
46cdf0e10cSrcweir 
47cdf0e10cSrcweir // namespace
48cdf0e10cSrcweir using namespace com::sun::star;
49cdf0e10cSrcweir 
50cdf0e10cSrcweir namespace framework
51cdf0e10cSrcweir {
52cdf0e10cSrcweir 
hasEmptySize(const::Size & aSize)53cdf0e10cSrcweir bool hasEmptySize( const:: Size& aSize )
54cdf0e10cSrcweir {
55cdf0e10cSrcweir     return ( aSize.Width() == 0 ) && ( aSize.Height() == 0 );
56cdf0e10cSrcweir }
57cdf0e10cSrcweir 
hasDefaultPosValue(const::Point & aPos)58cdf0e10cSrcweir bool hasDefaultPosValue( const ::Point& aPos )
59cdf0e10cSrcweir {
60cdf0e10cSrcweir     return (( aPos.X() == SAL_MAX_INT32 ) || ( aPos.Y() == SAL_MAX_INT32 ));
61cdf0e10cSrcweir }
62cdf0e10cSrcweir 
isDefaultPos(const::com::sun::star::awt::Point & aPos)63cdf0e10cSrcweir bool isDefaultPos( const ::com::sun::star::awt::Point& aPos )
64cdf0e10cSrcweir {
65cdf0e10cSrcweir     return (( aPos.X == SAL_MAX_INT32 ) && ( aPos.Y == SAL_MAX_INT32 ));
66cdf0e10cSrcweir }
67cdf0e10cSrcweir 
isDefaultPos(const::Point & aPos)68cdf0e10cSrcweir bool isDefaultPos( const ::Point& aPos )
69cdf0e10cSrcweir {
70cdf0e10cSrcweir     return (( aPos.X() == SAL_MAX_INT32 ) && ( aPos.Y() == SAL_MAX_INT32 ));
71cdf0e10cSrcweir }
72cdf0e10cSrcweir 
isReverseOrderDockingArea(const sal_Int32 nDockArea)73cdf0e10cSrcweir bool isReverseOrderDockingArea( const sal_Int32 nDockArea )
74cdf0e10cSrcweir {
75cdf0e10cSrcweir     ui::DockingArea eDockArea = static_cast< ui::DockingArea >( nDockArea );
76cdf0e10cSrcweir     return (( eDockArea == ui::DockingArea_DOCKINGAREA_BOTTOM ) ||
77cdf0e10cSrcweir             ( eDockArea == ui::DockingArea_DOCKINGAREA_RIGHT ));
78cdf0e10cSrcweir }
79cdf0e10cSrcweir 
isToolboxHorizontalAligned(ToolBox * pToolBox)80cdf0e10cSrcweir bool isToolboxHorizontalAligned( ToolBox* pToolBox )
81cdf0e10cSrcweir {
82cdf0e10cSrcweir     if ( pToolBox )
83cdf0e10cSrcweir         return (( pToolBox->GetAlign() == WINDOWALIGN_TOP ) || ( pToolBox->GetAlign() == WINDOWALIGN_BOTTOM ));
84cdf0e10cSrcweir     return false;
85cdf0e10cSrcweir }
86cdf0e10cSrcweir 
isHorizontalDockingArea(const ui::DockingArea & nDockingArea)87cdf0e10cSrcweir bool isHorizontalDockingArea( const ui::DockingArea& nDockingArea )
88cdf0e10cSrcweir {
89cdf0e10cSrcweir     return (( nDockingArea == ui::DockingArea_DOCKINGAREA_TOP ) ||
90cdf0e10cSrcweir             ( nDockingArea == ui::DockingArea_DOCKINGAREA_BOTTOM ));
91cdf0e10cSrcweir }
92cdf0e10cSrcweir 
isHorizontalDockingArea(const sal_Int32 nDockArea)93cdf0e10cSrcweir bool isHorizontalDockingArea( const sal_Int32 nDockArea )
94cdf0e10cSrcweir {
95cdf0e10cSrcweir   return isHorizontalDockingArea(static_cast< ui::DockingArea >( nDockArea ));
96cdf0e10cSrcweir }
97cdf0e10cSrcweir 
retrieveToolbarNameFromHelpURL(Window * pWindow)98cdf0e10cSrcweir ::rtl::OUString retrieveToolbarNameFromHelpURL( Window* pWindow )
99cdf0e10cSrcweir {
100cdf0e10cSrcweir     ::rtl::OUString aToolbarName;
101cdf0e10cSrcweir 
102cdf0e10cSrcweir     if ( pWindow->GetType() == WINDOW_TOOLBOX )
103cdf0e10cSrcweir     {
104cdf0e10cSrcweir         ToolBox* pToolBox = dynamic_cast<ToolBox *>( pWindow );
105cdf0e10cSrcweir         if ( pToolBox )
106cdf0e10cSrcweir         {
107cdf0e10cSrcweir             aToolbarName = rtl::OStringToOUString( pToolBox->GetHelpId(), RTL_TEXTENCODING_UTF8 );
108cdf0e10cSrcweir             sal_Int32 i = aToolbarName.lastIndexOf( ':' );
109cdf0e10cSrcweir             if (( aToolbarName.getLength() > 0 ) && ( i > 0 ) && (( i+ 1 ) < aToolbarName.getLength() ))
110cdf0e10cSrcweir                 aToolbarName = aToolbarName.copy( i+1 ); // Remove ".HelpId:" protocol from toolbar name
111cdf0e10cSrcweir             else
112cdf0e10cSrcweir               aToolbarName = ::rtl::OUString();
113cdf0e10cSrcweir         }
114cdf0e10cSrcweir     }
115cdf0e10cSrcweir     return aToolbarName;
116cdf0e10cSrcweir }
117cdf0e10cSrcweir 
getToolboxPtr(Window * pWindow)118cdf0e10cSrcweir ToolBox* getToolboxPtr( Window* pWindow )
119cdf0e10cSrcweir {
120cdf0e10cSrcweir     ToolBox* pToolbox(NULL);
121cdf0e10cSrcweir     if ( pWindow->GetType() == WINDOW_TOOLBOX )
122cdf0e10cSrcweir         pToolbox = dynamic_cast<ToolBox*>( pWindow );
123cdf0e10cSrcweir     return pToolbox;
124cdf0e10cSrcweir }
125cdf0e10cSrcweir 
getWindowFromXUIElement(const uno::Reference<ui::XUIElement> & xUIElement)126cdf0e10cSrcweir Window* getWindowFromXUIElement( const uno::Reference< ui::XUIElement >& xUIElement )
127cdf0e10cSrcweir {
128cdf0e10cSrcweir     vos::OGuard aGuard( Application::GetSolarMutex() );
129cdf0e10cSrcweir     uno::Reference< awt::XWindow > xWindow;
130cdf0e10cSrcweir     if ( xUIElement.is() )
131cdf0e10cSrcweir         xWindow = uno::Reference< awt::XWindow >( xUIElement->getRealInterface(), uno::UNO_QUERY );
132cdf0e10cSrcweir     return VCLUnoHelper::GetWindow( xWindow );
133cdf0e10cSrcweir }
134cdf0e10cSrcweir 
getTopSystemWindow(const uno::Reference<awt::XWindow> & xWindow)135cdf0e10cSrcweir SystemWindow* getTopSystemWindow( const uno::Reference< awt::XWindow >& xWindow )
136cdf0e10cSrcweir {
137cdf0e10cSrcweir     Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
138cdf0e10cSrcweir     while ( pWindow && !pWindow->IsSystemWindow() )
139cdf0e10cSrcweir         pWindow = pWindow->GetParent();
140cdf0e10cSrcweir 
141cdf0e10cSrcweir     if ( pWindow )
142cdf0e10cSrcweir         return (SystemWindow *)pWindow;
143cdf0e10cSrcweir     else
144cdf0e10cSrcweir         return 0;
145cdf0e10cSrcweir }
146cdf0e10cSrcweir 
setZeroRectangle(::Rectangle & rRect)147cdf0e10cSrcweir void setZeroRectangle( ::Rectangle& rRect )
148cdf0e10cSrcweir {
149cdf0e10cSrcweir     rRect.setX(0);
150cdf0e10cSrcweir     rRect.setY(0);
151cdf0e10cSrcweir     rRect.setWidth(0);
152cdf0e10cSrcweir     rRect.setHeight(0);
153cdf0e10cSrcweir }
154cdf0e10cSrcweir 
155cdf0e10cSrcweir // ATTENTION!
156cdf0e10cSrcweir // This value is directly copied from the sfx2 project.
157cdf0e10cSrcweir // You have to change BOTH values, see sfx2/inc/sfx2/sfxsids.hrc (SID_DOCKWIN_START)
158cdf0e10cSrcweir static const sal_Int32 DOCKWIN_ID_BASE = 9800;
159cdf0e10cSrcweir 
lcl_checkUIElement(const uno::Reference<ui::XUIElement> & xUIElement,awt::Rectangle & _rPosSize,uno::Reference<awt::XWindow> & _xWindow)160cdf0e10cSrcweir bool lcl_checkUIElement(const uno::Reference< ui::XUIElement >& xUIElement, awt::Rectangle& _rPosSize, uno::Reference< awt::XWindow >& _xWindow)
161cdf0e10cSrcweir {
162cdf0e10cSrcweir     bool bRet = xUIElement.is();
163cdf0e10cSrcweir     if ( bRet )
164cdf0e10cSrcweir     {
165cdf0e10cSrcweir         vos::OGuard     aGuard( Application::GetSolarMutex() );
166cdf0e10cSrcweir         _xWindow.set( xUIElement->getRealInterface(), uno::UNO_QUERY );
167cdf0e10cSrcweir         _rPosSize = _xWindow->getPosSize();
168cdf0e10cSrcweir 
169cdf0e10cSrcweir         Window* pWindow = VCLUnoHelper::GetWindow( _xWindow );
170cdf0e10cSrcweir         if ( pWindow->GetType() == WINDOW_TOOLBOX )
171cdf0e10cSrcweir         {
172cdf0e10cSrcweir             ::Size aSize = ((ToolBox*)pWindow)->CalcWindowSizePixel( 1 );
173cdf0e10cSrcweir             _rPosSize.Width = aSize.Width();
174cdf0e10cSrcweir             _rPosSize.Height = aSize.Height();
175cdf0e10cSrcweir         }
176cdf0e10cSrcweir     } // if ( xUIElement.is() )
177cdf0e10cSrcweir     return bRet;
178cdf0e10cSrcweir }
179cdf0e10cSrcweir 
createToolkitWindow(const uno::Reference<lang::XMultiServiceFactory> & rFactory,const uno::Reference<awt::XWindowPeer> & rParent,const char * pService)180cdf0e10cSrcweir uno::Reference< awt::XWindowPeer > createToolkitWindow( const uno::Reference< lang::XMultiServiceFactory >& rFactory, const uno::Reference< awt::XWindowPeer >& rParent, const char* pService )
181cdf0e10cSrcweir {
182cdf0e10cSrcweir     const rtl::OUString aAWTToolkit( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.Toolkit" ));
183cdf0e10cSrcweir 
184cdf0e10cSrcweir     uno::Reference< awt::XWindowPeer > xPeer;
185cdf0e10cSrcweir     if ( rFactory.is() )
186cdf0e10cSrcweir     {
187cdf0e10cSrcweir         uno::Reference< awt::XToolkit > xToolkit( rFactory->createInstance( aAWTToolkit ), uno::UNO_QUERY_THROW );
188cdf0e10cSrcweir         if ( xToolkit.is() )
189cdf0e10cSrcweir         {
190cdf0e10cSrcweir             // describe window properties.
191cdf0e10cSrcweir             css::awt::WindowDescriptor aDescriptor;
192cdf0e10cSrcweir             aDescriptor.Type                =   awt::WindowClass_SIMPLE;
193cdf0e10cSrcweir             aDescriptor.WindowServiceName   =   ::rtl::OUString::createFromAscii( pService );
194cdf0e10cSrcweir             aDescriptor.ParentIndex         =   -1;
195cdf0e10cSrcweir             aDescriptor.Parent              =   uno::Reference< awt::XWindowPeer >( rParent, uno::UNO_QUERY );
196cdf0e10cSrcweir             aDescriptor.Bounds              =   awt::Rectangle(0,0,0,0);
197cdf0e10cSrcweir             aDescriptor.WindowAttributes    =   0;
198cdf0e10cSrcweir 
199cdf0e10cSrcweir             // create a awt window
200cdf0e10cSrcweir             xPeer = xToolkit->createWindow( aDescriptor );
201cdf0e10cSrcweir         }
202cdf0e10cSrcweir     }
203cdf0e10cSrcweir 
204cdf0e10cSrcweir     return xPeer;
205cdf0e10cSrcweir }
206cdf0e10cSrcweir 
207cdf0e10cSrcweir // convert alignment constant to vcl's WindowAlign type
ImplConvertAlignment(sal_Int16 aAlignment)208cdf0e10cSrcweir WindowAlign ImplConvertAlignment( sal_Int16 aAlignment )
209cdf0e10cSrcweir {
210cdf0e10cSrcweir     if ( aAlignment == ui::DockingArea_DOCKINGAREA_LEFT )
211cdf0e10cSrcweir         return WINDOWALIGN_LEFT;
212cdf0e10cSrcweir     else if ( aAlignment == ui::DockingArea_DOCKINGAREA_RIGHT )
213cdf0e10cSrcweir         return WINDOWALIGN_RIGHT;
214cdf0e10cSrcweir     else if ( aAlignment == ui::DockingArea_DOCKINGAREA_TOP )
215cdf0e10cSrcweir         return WINDOWALIGN_TOP;
216cdf0e10cSrcweir     else
217cdf0e10cSrcweir         return WINDOWALIGN_BOTTOM;
218cdf0e10cSrcweir }
219cdf0e10cSrcweir 
getElementTypeFromResourceURL(const::rtl::OUString & aResourceURL)220cdf0e10cSrcweir ::rtl::OUString getElementTypeFromResourceURL( const ::rtl::OUString& aResourceURL )
221cdf0e10cSrcweir {
222cdf0e10cSrcweir     ::rtl::OUString aType;
223cdf0e10cSrcweir 
224cdf0e10cSrcweir     ::rtl::OUString aUIResourceURL( UIRESOURCE_URL );
225cdf0e10cSrcweir     if ( aResourceURL.indexOf( aUIResourceURL ) == 0 )
226cdf0e10cSrcweir     {
227cdf0e10cSrcweir         sal_Int32       nIndex = 0;
228cdf0e10cSrcweir         ::rtl::OUString aPathPart   = aResourceURL.copy( aUIResourceURL.getLength() );
229cdf0e10cSrcweir         ::rtl::OUString aUIResource = aPathPart.getToken( 0, (sal_Unicode)'/', nIndex );
230cdf0e10cSrcweir 
231cdf0e10cSrcweir         return aPathPart.getToken( 0, (sal_Unicode)'/', nIndex );
232cdf0e10cSrcweir     }
233cdf0e10cSrcweir 
234cdf0e10cSrcweir     return aType;
235cdf0e10cSrcweir }
236cdf0e10cSrcweir 
parseResourceURL(const rtl::OUString & aResourceURL,rtl::OUString & aElementType,rtl::OUString & aElementName)237cdf0e10cSrcweir void parseResourceURL( const rtl::OUString& aResourceURL, rtl::OUString& aElementType, rtl::OUString& aElementName )
238cdf0e10cSrcweir {
239cdf0e10cSrcweir     ::rtl::OUString aUIResourceURL( UIRESOURCE_URL );
240cdf0e10cSrcweir     if ( aResourceURL.indexOf( aUIResourceURL ) == 0 )
241cdf0e10cSrcweir     {
242cdf0e10cSrcweir         sal_Int32       nIndex = 0;
243cdf0e10cSrcweir         ::rtl::OUString aPathPart   = aResourceURL.copy( aUIResourceURL.getLength() );
244cdf0e10cSrcweir         ::rtl::OUString aUIResource = aPathPart.getToken( 0, (sal_Unicode)'/', nIndex );
245cdf0e10cSrcweir 
246cdf0e10cSrcweir         aElementType = aPathPart.getToken( 0, (sal_Unicode)'/', nIndex );
247cdf0e10cSrcweir         aElementName = aPathPart.getToken( 0, (sal_Unicode)'/', nIndex );
248cdf0e10cSrcweir     }
249cdf0e10cSrcweir }
250cdf0e10cSrcweir 
putRectangleValueToAWT(const::Rectangle & rRect)251cdf0e10cSrcweir ::com::sun::star::awt::Rectangle putRectangleValueToAWT( const ::Rectangle& rRect )
252cdf0e10cSrcweir {
253cdf0e10cSrcweir     css::awt::Rectangle aRect;
254cdf0e10cSrcweir     aRect.X = rRect.Left();
255cdf0e10cSrcweir     aRect.Y = rRect.Top();
256cdf0e10cSrcweir     aRect.Width = rRect.Right();
257cdf0e10cSrcweir     aRect.Height = rRect.Bottom();
258cdf0e10cSrcweir 
259cdf0e10cSrcweir     return aRect;
260cdf0e10cSrcweir }
261cdf0e10cSrcweir 
putAWTToRectangle(const::com::sun::star::awt::Rectangle & rRect)262cdf0e10cSrcweir ::Rectangle putAWTToRectangle( const ::com::sun::star::awt::Rectangle& rRect )
263cdf0e10cSrcweir {
264cdf0e10cSrcweir     ::Rectangle aRect;
265cdf0e10cSrcweir     aRect.Left() = rRect.X;
266cdf0e10cSrcweir     aRect.Top() = rRect.Y;
267cdf0e10cSrcweir     aRect.Right() = rRect.Width;
268cdf0e10cSrcweir     aRect.Bottom() = rRect.Height;
269cdf0e10cSrcweir 
270cdf0e10cSrcweir     return aRect;
271cdf0e10cSrcweir }
272cdf0e10cSrcweir 
convertRectangleToAWT(const::Rectangle & rRect)273cdf0e10cSrcweir css::awt::Rectangle convertRectangleToAWT( const ::Rectangle& rRect )
274cdf0e10cSrcweir {
275cdf0e10cSrcweir     css::awt::Rectangle aRect;
276cdf0e10cSrcweir     aRect.X = rRect.Left();
277cdf0e10cSrcweir     aRect.Y = rRect.Top();
278cdf0e10cSrcweir     aRect.Width = rRect.GetWidth();
279cdf0e10cSrcweir     aRect.Height = rRect.GetHeight();
280cdf0e10cSrcweir     return aRect;
281cdf0e10cSrcweir }
282cdf0e10cSrcweir 
convertAWTToRectangle(const::com::sun::star::awt::Rectangle & rRect)283cdf0e10cSrcweir ::Rectangle convertAWTToRectangle( const ::com::sun::star::awt::Rectangle& rRect )
284cdf0e10cSrcweir {
285cdf0e10cSrcweir     ::Rectangle aRect;
286cdf0e10cSrcweir     aRect.Left()   = rRect.X;
287cdf0e10cSrcweir     aRect.Top()    = rRect.Y;
288cdf0e10cSrcweir     aRect.Right()  = rRect.X + rRect.Width;
289cdf0e10cSrcweir     aRect.Bottom() = rRect.Y + rRect.Height;
290cdf0e10cSrcweir 
291cdf0e10cSrcweir     return aRect;
292cdf0e10cSrcweir }
293cdf0e10cSrcweir 
equalRectangles(const css::awt::Rectangle & rRect1,const css::awt::Rectangle & rRect2)294cdf0e10cSrcweir bool equalRectangles( const css::awt::Rectangle& rRect1,
295cdf0e10cSrcweir                       const css::awt::Rectangle& rRect2 )
296cdf0e10cSrcweir {
297cdf0e10cSrcweir     return (( rRect1.X == rRect2.X ) &&
298cdf0e10cSrcweir             ( rRect1.Y == rRect2.Y ) &&
299cdf0e10cSrcweir             ( rRect1.Width == rRect2.Width ) &&
300cdf0e10cSrcweir             ( rRect1.Height == rRect2.Height ));
301cdf0e10cSrcweir }
302cdf0e10cSrcweir 
impl_getModelFromFrame(const uno::Reference<frame::XFrame> & rFrame)303cdf0e10cSrcweir uno::Reference< frame::XModel > impl_getModelFromFrame( const uno::Reference< frame::XFrame >& rFrame )
304cdf0e10cSrcweir {
305cdf0e10cSrcweir     // Query for the model to get check the context information
306cdf0e10cSrcweir     uno::Reference< frame::XModel > xModel;
307cdf0e10cSrcweir         if ( rFrame.is() )
308cdf0e10cSrcweir         {
309cdf0e10cSrcweir         uno::Reference< frame::XController > xController( rFrame->getController(), uno::UNO_QUERY );
310cdf0e10cSrcweir             if ( xController.is() )
311cdf0e10cSrcweir                 xModel = xController->getModel();
312cdf0e10cSrcweir         }
313cdf0e10cSrcweir 
314cdf0e10cSrcweir     return xModel;
315cdf0e10cSrcweir }
316cdf0e10cSrcweir 
implts_isPreviewModel(const uno::Reference<frame::XModel> & xModel)317cdf0e10cSrcweir sal_Bool implts_isPreviewModel( const uno::Reference< frame::XModel >& xModel )
318cdf0e10cSrcweir {
319cdf0e10cSrcweir     if ( xModel.is() )
320cdf0e10cSrcweir     {
321cdf0e10cSrcweir         ::comphelper::MediaDescriptor aDesc( xModel->getArgs() );
322cdf0e10cSrcweir         return aDesc.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_PREVIEW(), (sal_Bool)sal_False);
323cdf0e10cSrcweir     }
324cdf0e10cSrcweir     else
325cdf0e10cSrcweir         return sal_False;
326cdf0e10cSrcweir }
327cdf0e10cSrcweir 
implts_isFrameOrWindowTop(const uno::Reference<frame::XFrame> & xFrame)328cdf0e10cSrcweir sal_Bool implts_isFrameOrWindowTop( const uno::Reference< frame::XFrame >& xFrame )
329cdf0e10cSrcweir {
330cdf0e10cSrcweir     if (xFrame->isTop())
331cdf0e10cSrcweir         return sal_True;
332cdf0e10cSrcweir 
333cdf0e10cSrcweir     uno::Reference< awt::XTopWindow > xWindowCheck(xFrame->getContainerWindow(), uno::UNO_QUERY); // dont use _THROW here ... its a check only
334cdf0e10cSrcweir     if (xWindowCheck.is())
335cdf0e10cSrcweir     {
336cdf0e10cSrcweir         // --> PB 2007-06-18 #i76867# top and system window is required.
337cdf0e10cSrcweir         ::vos::OGuard aSolarLock(&Application::GetSolarMutex());
338cdf0e10cSrcweir         uno::Reference< awt::XWindow > xWindow( xWindowCheck, uno::UNO_QUERY );
339cdf0e10cSrcweir         Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
340cdf0e10cSrcweir         return ( pWindow && pWindow->IsSystemWindow() );
341cdf0e10cSrcweir         // <--
342cdf0e10cSrcweir     }
343cdf0e10cSrcweir 
344cdf0e10cSrcweir     return sal_False;
345cdf0e10cSrcweir }
346cdf0e10cSrcweir 
impl_setDockingWindowVisibility(const css::uno::Reference<css::lang::XMultiServiceFactory> & rSMGR,const css::uno::Reference<css::frame::XFrame> & rFrame,const::rtl::OUString & rDockingWindowName,bool bVisible)347cdf0e10cSrcweir 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 )
348cdf0e10cSrcweir {
349cdf0e10cSrcweir     const ::rtl::OUString aDockWinPrefixCommand( RTL_CONSTASCII_USTRINGPARAM( "DockingWindow" ));
350cdf0e10cSrcweir     css::uno::WeakReference< css::frame::XDispatchHelper > xDispatchHelper;
351cdf0e10cSrcweir 
352cdf0e10cSrcweir     sal_Int32 nID    = rDockingWindowName.toInt32();
353cdf0e10cSrcweir     sal_Int32 nIndex = nID - DOCKWIN_ID_BASE;
354cdf0e10cSrcweir 
355cdf0e10cSrcweir     css::uno::Reference< css::frame::XDispatchProvider > xProvider(rFrame, css::uno::UNO_QUERY);
356cdf0e10cSrcweir     if ( nIndex >= 0 && xProvider.is() )
357cdf0e10cSrcweir     {
358cdf0e10cSrcweir         ::rtl::OUString aDockWinCommand( RTL_CONSTASCII_USTRINGPARAM( ".uno:" ));
359cdf0e10cSrcweir         ::rtl::OUString aDockWinArgName( aDockWinPrefixCommand );
360cdf0e10cSrcweir 
361cdf0e10cSrcweir         aDockWinArgName += ::rtl::OUString::valueOf( nIndex );
362cdf0e10cSrcweir 
363cdf0e10cSrcweir         css::uno::Sequence< css::beans::PropertyValue > aArgs(1);
364cdf0e10cSrcweir         aArgs[0].Name  = aDockWinArgName;
365cdf0e10cSrcweir         aArgs[0].Value = css::uno::makeAny( bVisible );
366cdf0e10cSrcweir 
367cdf0e10cSrcweir         css::uno::Reference< css::frame::XDispatchHelper > xDispatcher( xDispatchHelper );
368cdf0e10cSrcweir         if ( !xDispatcher.is())
369cdf0e10cSrcweir         {
370cdf0e10cSrcweir             xDispatcher = css::uno::Reference< css::frame::XDispatchHelper >(
371cdf0e10cSrcweir                 rSMGR->createInstance(SERVICENAME_DISPATCHHELPER), css::uno::UNO_QUERY_THROW);
372cdf0e10cSrcweir         }
373cdf0e10cSrcweir 
374cdf0e10cSrcweir         aDockWinCommand = aDockWinCommand + aDockWinArgName;
375cdf0e10cSrcweir         xDispatcher->executeDispatch(
376cdf0e10cSrcweir             xProvider,
377cdf0e10cSrcweir             aDockWinCommand,
378cdf0e10cSrcweir             ::rtl::OUString::createFromAscii("_self"),
379cdf0e10cSrcweir             0,
380cdf0e10cSrcweir             aArgs);
381cdf0e10cSrcweir     }
382cdf0e10cSrcweir }
383cdf0e10cSrcweir 
impl_addWindowListeners(const css::uno::Reference<css::uno::XInterface> & xThis,const css::uno::Reference<css::ui::XUIElement> & xUIElement)384cdf0e10cSrcweir void impl_addWindowListeners(
385cdf0e10cSrcweir     const css::uno::Reference< css::uno::XInterface >& xThis,
386cdf0e10cSrcweir     const css::uno::Reference< css::ui::XUIElement >& xUIElement )
387cdf0e10cSrcweir {
388cdf0e10cSrcweir     css::uno::Reference< css::awt::XWindow > xWindow( xUIElement->getRealInterface(), css::uno::UNO_QUERY );
389cdf0e10cSrcweir     css::uno::Reference< css::awt::XDockableWindow > xDockWindow( xUIElement->getRealInterface(), css::uno::UNO_QUERY );
390cdf0e10cSrcweir     if ( xDockWindow.is() && xWindow.is() )
391cdf0e10cSrcweir     {
392cdf0e10cSrcweir         try
393cdf0e10cSrcweir         {
394cdf0e10cSrcweir             xDockWindow->addDockableWindowListener(
395cdf0e10cSrcweir                 css::uno::Reference< css::awt::XDockableWindowListener >(
396cdf0e10cSrcweir                     xThis, css::uno::UNO_QUERY ));
397cdf0e10cSrcweir             xWindow->addWindowListener(
398cdf0e10cSrcweir                 css::uno::Reference< css::awt::XWindowListener >(
399cdf0e10cSrcweir                     xThis, css::uno::UNO_QUERY ));
400cdf0e10cSrcweir             xDockWindow->enableDocking( sal_True );
401cdf0e10cSrcweir         }
402cdf0e10cSrcweir         catch ( css::uno::Exception& )
403cdf0e10cSrcweir         {
404cdf0e10cSrcweir         }
405cdf0e10cSrcweir     }
406cdf0e10cSrcweir }
407cdf0e10cSrcweir 
408cdf0e10cSrcweir } // namespace framework
409