Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2008 by Sun Microsystems, Inc.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "helpers.hxx"
30 : : #include <threadhelp/resetableguard.hxx>
31 : : #include <services.h>
32 : :
33 : : #include <com/sun/star/ui/DockingArea.hpp>
34 : : #include <com/sun/star/awt/XTopWindow.hpp>
35 : : #include <com/sun/star/frame/XDispatchHelper.hpp>
36 : : #include <com/sun/star/awt/XDockableWindow.hpp>
37 : : #include <com/sun/star/awt/XDockableWindowListener.hpp>
38 : : #include <com/sun/star/awt/XWindowListener.hpp>
39 : : #include <com/sun/star/ui/XUIElement.hpp>
40 : :
41 : : #include <comphelper/mediadescriptor.hxx>
42 : : #include <vcl/svapp.hxx>
43 : : #include <toolkit/unohlp.hxx>
44 : :
45 : : using namespace com::sun::star;
46 : :
47 : : namespace framework
48 : : {
49 : :
50 : 0 : bool hasEmptySize( const ::com::sun::star::awt::Size& rSize )
51 : : {
52 [ # # ][ # # ]: 0 : return ( rSize.Width == 0 ) && ( rSize.Height == 0 );
53 : : }
54 : :
55 : 0 : bool hasDefaultPosValue( const ::com::sun::star::awt::Point& rPos )
56 : : {
57 [ # # ][ # # ]: 0 : return (( rPos.X == SAL_MAX_INT32 ) || ( rPos.Y == SAL_MAX_INT32 ));
58 : : }
59 : :
60 : 3709 : bool isDefaultPos( const ::com::sun::star::awt::Point& rPos )
61 : : {
62 [ + + ][ + - ]: 3709 : return (( rPos.X == SAL_MAX_INT32 ) && ( rPos.Y == SAL_MAX_INT32 ));
63 : : }
64 : :
65 : 20620 : bool isReverseOrderDockingArea( const sal_Int32 nDockArea )
66 : : {
67 : 20620 : ui::DockingArea eDockArea = static_cast< ui::DockingArea >( nDockArea );
68 : : return (( eDockArea == ui::DockingArea_DOCKINGAREA_BOTTOM ) ||
69 [ + + ][ + + ]: 20620 : ( eDockArea == ui::DockingArea_DOCKINGAREA_RIGHT ));
70 : : }
71 : :
72 : 0 : bool isToolboxHorizontalAligned( ToolBox* pToolBox )
73 : : {
74 [ # # ]: 0 : if ( pToolBox )
75 [ # # ][ # # ]: 0 : return (( pToolBox->GetAlign() == WINDOWALIGN_TOP ) || ( pToolBox->GetAlign() == WINDOWALIGN_BOTTOM ));
76 : 0 : return false;
77 : : }
78 : :
79 : 35164 : bool isHorizontalDockingArea( const ui::DockingArea& nDockingArea )
80 : : {
81 : : return (( nDockingArea == ui::DockingArea_DOCKINGAREA_TOP ) ||
82 [ + + ][ + - ]: 35164 : ( nDockingArea == ui::DockingArea_DOCKINGAREA_BOTTOM ));
83 : : }
84 : :
85 : 26194 : bool isHorizontalDockingArea( const sal_Int32 nDockArea )
86 : : {
87 : 26194 : return isHorizontalDockingArea(static_cast< ui::DockingArea >( nDockArea ));
88 : : }
89 : :
90 : 107920 : ::rtl::OUString retrieveToolbarNameFromHelpURL( Window* pWindow )
91 : : {
92 : 107920 : ::rtl::OUString aToolbarName;
93 : :
94 [ + - ][ + - ]: 107920 : if ( pWindow->GetType() == WINDOW_TOOLBOX )
95 : : {
96 [ - + ]: 107920 : ToolBox* pToolBox = dynamic_cast<ToolBox *>( pWindow );
97 [ + - ]: 107920 : if ( pToolBox )
98 : : {
99 [ + - ][ + - ]: 107920 : aToolbarName = rtl::OStringToOUString( pToolBox->GetHelpId(), RTL_TEXTENCODING_UTF8 );
100 : 107920 : sal_Int32 i = aToolbarName.lastIndexOf( ':' );
101 [ + + ][ + - ]: 107920 : if ( !aToolbarName.isEmpty() && ( i > 0 ) && (( i + 1 ) < aToolbarName.getLength() ))
[ + + ][ + + ]
102 : 90087 : aToolbarName = aToolbarName.copy( i+1 ); // Remove ".HelpId:" protocol from toolbar name
103 : : else
104 : 17833 : aToolbarName = ::rtl::OUString();
105 : : }
106 : : }
107 : 107920 : return aToolbarName;
108 : : }
109 : :
110 : 107920 : ToolBox* getToolboxPtr( Window* pWindow )
111 : : {
112 : 107920 : ToolBox* pToolbox(NULL);
113 [ + - ]: 107920 : if ( pWindow->GetType() == WINDOW_TOOLBOX )
114 [ - + ]: 107920 : pToolbox = dynamic_cast<ToolBox*>( pWindow );
115 : 107920 : return pToolbox;
116 : : }
117 : :
118 : 9741 : Window* getWindowFromXUIElement( const uno::Reference< ui::XUIElement >& xUIElement )
119 : : {
120 [ + - ]: 9741 : SolarMutexGuard aGuard;
121 : 9741 : uno::Reference< awt::XWindow > xWindow;
122 [ + - ]: 9741 : if ( xUIElement.is() )
123 [ + - ][ + - ]: 9741 : xWindow = uno::Reference< awt::XWindow >( xUIElement->getRealInterface(), uno::UNO_QUERY );
[ + - ][ + - ]
124 [ + - ][ + - ]: 9741 : return VCLUnoHelper::GetWindow( xWindow );
125 : : }
126 : :
127 : 17550 : SystemWindow* getTopSystemWindow( const uno::Reference< awt::XWindow >& xWindow )
128 : : {
129 : 17550 : Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
130 [ + - ][ + + ]: 17576 : while ( pWindow && !pWindow->IsSystemWindow() )
[ + + ]
131 : 26 : pWindow = pWindow->GetParent();
132 : :
133 [ + - ]: 17550 : if ( pWindow )
134 : 17550 : return (SystemWindow *)pWindow;
135 : : else
136 : 17550 : return 0;
137 : : }
138 : :
139 : 9489 : void setZeroRectangle( ::Rectangle& rRect )
140 : : {
141 : 9489 : rRect.setX(0);
142 : 9489 : rRect.setY(0);
143 : 9489 : rRect.setWidth(0);
144 : 9489 : rRect.setHeight(0);
145 : 9489 : }
146 : :
147 : : // ATTENTION!
148 : : // This value is directly copied from the sfx2 project.
149 : : // You have to change BOTH values, see sfx2/inc/sfx2/sfxsids.hrc (SID_DOCKWIN_START)
150 : : static const sal_Int32 DOCKWIN_ID_BASE = 9800;
151 : :
152 : 8688 : bool lcl_checkUIElement(const uno::Reference< ui::XUIElement >& xUIElement, awt::Rectangle& _rPosSize, uno::Reference< awt::XWindow >& _xWindow)
153 : : {
154 : 8688 : bool bRet = xUIElement.is();
155 [ + - ]: 8688 : if ( bRet )
156 : : {
157 [ + - ]: 8688 : SolarMutexGuard aGuard;
158 [ + - ][ + - ]: 8688 : _xWindow.set( xUIElement->getRealInterface(), uno::UNO_QUERY );
[ + - ]
159 [ + - ][ + - ]: 8688 : _rPosSize = _xWindow->getPosSize();
160 : :
161 [ + - ]: 8688 : Window* pWindow = VCLUnoHelper::GetWindow( _xWindow );
162 [ + - ][ + - ]: 8688 : if ( pWindow->GetType() == WINDOW_TOOLBOX )
163 : : {
164 [ + - ]: 8688 : ::Size aSize = ((ToolBox*)pWindow)->CalcWindowSizePixel( 1 );
165 : 8688 : _rPosSize.Width = aSize.Width();
166 : 8688 : _rPosSize.Height = aSize.Height();
167 [ + - ]: 8688 : }
168 : : } // if ( xUIElement.is() )
169 : 8688 : return bRet;
170 : : }
171 : :
172 : 14080 : uno::Reference< awt::XWindowPeer > createToolkitWindow( const uno::Reference< lang::XMultiServiceFactory >& rFactory, const uno::Reference< awt::XWindowPeer >& rParent, const char* pService )
173 : : {
174 [ + - ]: 14080 : const rtl::OUString aAWTToolkit( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.Toolkit" ));
175 : :
176 : 14080 : uno::Reference< awt::XWindowPeer > xPeer;
177 [ + - ]: 14080 : if ( rFactory.is() )
178 : : {
179 [ + - ][ + - ]: 14080 : uno::Reference< awt::XToolkit > xToolkit( rFactory->createInstance( aAWTToolkit ), uno::UNO_QUERY_THROW );
[ + - ]
180 [ + - ]: 14080 : if ( xToolkit.is() )
181 : : {
182 : : // describe window properties.
183 [ + - ]: 14080 : css::awt::WindowDescriptor aDescriptor;
184 : 14080 : aDescriptor.Type = awt::WindowClass_SIMPLE;
185 : 14080 : aDescriptor.WindowServiceName = ::rtl::OUString::createFromAscii( pService );
186 : 14080 : aDescriptor.ParentIndex = -1;
187 [ + - ][ + - ]: 14080 : aDescriptor.Parent = uno::Reference< awt::XWindowPeer >( rParent, uno::UNO_QUERY );
188 : 14080 : aDescriptor.Bounds = awt::Rectangle(0,0,0,0);
189 : 14080 : aDescriptor.WindowAttributes = 0;
190 : :
191 : : // create a awt window
192 [ + - ][ + - ]: 14080 : xPeer = xToolkit->createWindow( aDescriptor );
[ + - ][ + - ]
193 : 14080 : }
194 : : }
195 : :
196 : 14080 : return xPeer;
197 : : }
198 : :
199 : : // convert alignment constant to vcl's WindowAlign type
200 : 3709 : WindowAlign ImplConvertAlignment( sal_Int16 aAlignment )
201 : : {
202 [ - + ]: 3709 : if ( aAlignment == ui::DockingArea_DOCKINGAREA_LEFT )
203 : 0 : return WINDOWALIGN_LEFT;
204 [ - + ]: 3709 : else if ( aAlignment == ui::DockingArea_DOCKINGAREA_RIGHT )
205 : 0 : return WINDOWALIGN_RIGHT;
206 [ + + ]: 3709 : else if ( aAlignment == ui::DockingArea_DOCKINGAREA_TOP )
207 : 3509 : return WINDOWALIGN_TOP;
208 : : else
209 : 3709 : return WINDOWALIGN_BOTTOM;
210 : : }
211 : :
212 : 16 : ::rtl::OUString getElementTypeFromResourceURL( const ::rtl::OUString& aResourceURL )
213 : : {
214 : 16 : ::rtl::OUString aType;
215 : :
216 [ + - ]: 16 : ::rtl::OUString aUIResourceURL( UIRESOURCE_URL );
217 [ + - ]: 16 : if ( aResourceURL.indexOf( aUIResourceURL ) == 0 )
218 : : {
219 : 16 : sal_Int32 nIndex = 0;
220 : 16 : ::rtl::OUString aPathPart = aResourceURL.copy( aUIResourceURL.getLength() );
221 : 16 : ::rtl::OUString aUIResource = aPathPart.getToken( 0, (sal_Unicode)'/', nIndex );
222 : :
223 : 16 : return aPathPart.getToken( 0, (sal_Unicode)'/', nIndex );
224 : : }
225 : :
226 : 16 : return aType;
227 : : }
228 : :
229 : 168302 : void parseResourceURL( const rtl::OUString& aResourceURL, rtl::OUString& aElementType, rtl::OUString& aElementName )
230 : : {
231 [ + - ]: 168302 : ::rtl::OUString aUIResourceURL( UIRESOURCE_URL );
232 [ + + ]: 168302 : if ( aResourceURL.indexOf( aUIResourceURL ) == 0 )
233 : : {
234 : 168292 : sal_Int32 nIndex = 0;
235 : 168292 : ::rtl::OUString aPathPart = aResourceURL.copy( aUIResourceURL.getLength() );
236 : 168292 : ::rtl::OUString aUIResource = aPathPart.getToken( 0, (sal_Unicode)'/', nIndex );
237 : :
238 : 168292 : aElementType = aPathPart.getToken( 0, (sal_Unicode)'/', nIndex );
239 : 168292 : aElementName = aPathPart.getToken( 0, (sal_Unicode)'/', nIndex );
240 : 168302 : }
241 : 168302 : }
242 : :
243 : 10374 : ::com::sun::star::awt::Rectangle putRectangleValueToAWT( const ::Rectangle& rRect )
244 : : {
245 : 10374 : css::awt::Rectangle aRect;
246 : 10374 : aRect.X = rRect.Left();
247 : 10374 : aRect.Y = rRect.Top();
248 : 10374 : aRect.Width = rRect.Right();
249 : 10374 : aRect.Height = rRect.Bottom();
250 : :
251 : 10374 : return aRect;
252 : : }
253 : :
254 : 5155 : ::Rectangle putAWTToRectangle( const ::com::sun::star::awt::Rectangle& rRect )
255 : : {
256 : 5155 : ::Rectangle aRect;
257 : 5155 : aRect.Left() = rRect.X;
258 : 5155 : aRect.Top() = rRect.Y;
259 : 5155 : aRect.Right() = rRect.Width;
260 : 5155 : aRect.Bottom() = rRect.Height;
261 : :
262 : 5155 : return aRect;
263 : : }
264 : :
265 : 5219 : bool equalRectangles( const css::awt::Rectangle& rRect1,
266 : : const css::awt::Rectangle& rRect2 )
267 : : {
268 : : return (( rRect1.X == rRect2.X ) &&
269 : : ( rRect1.Y == rRect2.Y ) &&
270 : : ( rRect1.Width == rRect2.Width ) &&
271 [ + - ][ + + ]: 5219 : ( rRect1.Height == rRect2.Height ));
[ + - ][ + + ]
272 : : }
273 : :
274 : 3536 : uno::Reference< frame::XModel > impl_getModelFromFrame( const uno::Reference< frame::XFrame >& rFrame )
275 : : {
276 : : // Query for the model to get check the context information
277 : 3536 : uno::Reference< frame::XModel > xModel;
278 [ + + ]: 3536 : if ( rFrame.is() )
279 : : {
280 [ + - ][ + - ]: 1789 : uno::Reference< frame::XController > xController( rFrame->getController(), uno::UNO_QUERY );
[ + - ]
281 [ + + ]: 1789 : if ( xController.is() )
282 [ + - ][ + - ]: 1789 : xModel = xController->getModel();
[ + - ]
283 : : }
284 : :
285 : 3536 : return xModel;
286 : : }
287 : :
288 : 1767 : sal_Bool implts_isPreviewModel( const uno::Reference< frame::XModel >& xModel )
289 : : {
290 [ + + ]: 1767 : if ( xModel.is() )
291 : : {
292 [ + - ][ + - ]: 16 : ::comphelper::MediaDescriptor aDesc( xModel->getArgs() );
[ + - ][ + - ]
293 [ + - ][ + - ]: 16 : return aDesc.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_PREVIEW(), (sal_Bool)sal_False);
[ + - ]
294 : : }
295 : : else
296 : 1767 : return sal_False;
297 : : }
298 : :
299 : 8598 : sal_Bool implts_isFrameOrWindowTop( const uno::Reference< frame::XFrame >& xFrame )
300 : : {
301 [ + - ][ + - ]: 8598 : if (xFrame->isTop())
[ + + ]
302 : 8596 : return sal_True;
303 : :
304 [ + - ][ + - ]: 2 : uno::Reference< awt::XTopWindow > xWindowCheck(xFrame->getContainerWindow(), uno::UNO_QUERY); // dont use _THROW here ... its a check only
[ + - ]
305 [ + - ]: 2 : if (xWindowCheck.is())
306 : : {
307 : : // #i76867# top and system window is required.
308 [ + - ]: 2 : SolarMutexGuard aGuard;
309 [ + - ]: 2 : uno::Reference< awt::XWindow > xWindow( xWindowCheck, uno::UNO_QUERY );
310 [ + - ]: 2 : Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
311 [ + - ][ + - ]: 2 : return ( pWindow && pWindow->IsSystemWindow() );
[ - + ][ + - ]
312 : : }
313 : :
314 : 8598 : return sal_False;
315 : : }
316 : :
317 : 0 : 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 )
318 : : {
319 [ # # ]: 0 : const ::rtl::OUString aDockWinPrefixCommand( RTL_CONSTASCII_USTRINGPARAM( "DockingWindow" ));
320 [ # # ]: 0 : css::uno::WeakReference< css::frame::XDispatchHelper > xDispatchHelper;
321 : :
322 : 0 : sal_Int32 nID = rDockingWindowName.toInt32();
323 : 0 : sal_Int32 nIndex = nID - DOCKWIN_ID_BASE;
324 : :
325 [ # # ]: 0 : css::uno::Reference< css::frame::XDispatchProvider > xProvider(rFrame, css::uno::UNO_QUERY);
326 [ # # ][ # # ]: 0 : if ( nIndex >= 0 && xProvider.is() )
[ # # ]
327 : : {
328 [ # # ]: 0 : ::rtl::OUString aDockWinCommand( RTL_CONSTASCII_USTRINGPARAM( ".uno:" ));
329 : 0 : ::rtl::OUString aDockWinArgName( aDockWinPrefixCommand );
330 : :
331 : 0 : aDockWinArgName += ::rtl::OUString::valueOf( nIndex );
332 : :
333 [ # # ]: 0 : css::uno::Sequence< css::beans::PropertyValue > aArgs(1);
334 [ # # ]: 0 : aArgs[0].Name = aDockWinArgName;
335 [ # # ][ # # ]: 0 : aArgs[0].Value = css::uno::makeAny( bVisible );
336 : :
337 [ # # ]: 0 : css::uno::Reference< css::frame::XDispatchHelper > xDispatcher( xDispatchHelper );
338 [ # # ]: 0 : if ( !xDispatcher.is())
339 : : {
340 : : xDispatcher = css::uno::Reference< css::frame::XDispatchHelper >(
341 [ # # ][ # # ]: 0 : rSMGR->createInstance(SERVICENAME_DISPATCHHELPER), css::uno::UNO_QUERY_THROW);
[ # # ][ # # ]
[ # # ]
342 : : }
343 : :
344 : 0 : aDockWinCommand = aDockWinCommand + aDockWinArgName;
345 [ # # ]: 0 : xDispatcher->executeDispatch(
346 : : xProvider,
347 : : aDockWinCommand,
348 : : ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_self")),
349 : : 0,
350 [ # # ][ # # ]: 0 : aArgs);
[ # # ]
351 [ # # ]: 0 : }
352 : 0 : }
353 : :
354 : 0 : void impl_addWindowListeners(
355 : : const css::uno::Reference< css::uno::XInterface >& xThis,
356 : : const css::uno::Reference< css::ui::XUIElement >& xUIElement )
357 : : {
358 [ # # ][ # # ]: 0 : css::uno::Reference< css::awt::XWindow > xWindow( xUIElement->getRealInterface(), css::uno::UNO_QUERY );
[ # # ]
359 [ # # ][ # # ]: 0 : css::uno::Reference< css::awt::XDockableWindow > xDockWindow( xUIElement->getRealInterface(), css::uno::UNO_QUERY );
[ # # ]
360 [ # # ][ # # ]: 0 : if ( xDockWindow.is() && xWindow.is() )
[ # # ]
361 : : {
362 : : try
363 : : {
364 [ # # ]: 0 : xDockWindow->addDockableWindowListener(
365 : : css::uno::Reference< css::awt::XDockableWindowListener >(
366 [ # # ][ # # ]: 0 : xThis, css::uno::UNO_QUERY ));
367 [ # # ]: 0 : xWindow->addWindowListener(
368 : : css::uno::Reference< css::awt::XWindowListener >(
369 [ # # ][ # # ]: 0 : xThis, css::uno::UNO_QUERY ));
[ # # ]
370 [ # # ][ # # ]: 0 : xDockWindow->enableDocking( sal_True );
371 : : }
372 [ # # ]: 0 : catch ( const css::uno::Exception& )
373 : : {
374 : : }
375 : 0 : }
376 : 0 : }
377 : :
378 : : } // namespace framework
379 : :
380 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|