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 2000, 2010 Oracle and/or its affiliates.
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 : :
30 : : #include <vcl/svapp.hxx>
31 : : #include <vcl/window.hxx>
32 : : #include <vcl/wall.hxx>
33 : : #include <toolkit/controls/tabpagemodel.hxx>
34 : : #include <toolkit/helper/property.hxx>
35 : : #include <toolkit/helper/unopropertyarrayhelper.hxx>
36 : : #include <toolkit/controls/stdtabcontroller.hxx>
37 : : #include <com/sun/star/awt/PosSize.hpp>
38 : : #include <com/sun/star/awt/WindowAttribute.hpp>
39 : : #include <com/sun/star/awt/UnoControlDialogModelProvider.hpp>
40 : : #include <com/sun/star/resource/XStringResourceResolver.hpp>
41 : : #include <com/sun/star/graphic/XGraphicProvider.hpp>
42 : : #include <cppuhelper/typeprovider.hxx>
43 : : #include <tools/debug.hxx>
44 : : #include <tools/diagnose_ex.h>
45 : : #include <comphelper/sequence.hxx>
46 : : #include <vcl/svapp.hxx>
47 : : #include <vcl/outdev.hxx>
48 : :
49 : : #include <toolkit/helper/vclunohelper.hxx>
50 : : #include <unotools/ucbstreamhelper.hxx>
51 : : #include <vcl/graph.hxx>
52 : : #include <vcl/image.hxx>
53 : : #include <toolkit/controls/geometrycontrolmodel.hxx>
54 : :
55 : : #include <map>
56 : : #include <algorithm>
57 : : #include <functional>
58 : : #include "osl/file.hxx"
59 : :
60 : : #include <com/sun/star/beans/XPropertySet.hpp>
61 : :
62 : : using namespace ::com::sun::star;
63 : : using namespace ::com::sun::star::uno;
64 : : using namespace ::com::sun::star::awt;
65 : : using namespace ::com::sun::star::lang;
66 : : using namespace ::com::sun::star::container;
67 : : using namespace ::com::sun::star::beans;
68 : : using namespace ::com::sun::star::util;
69 : :
70 : : ////HELPER
71 : : ::rtl::OUString getPhysicalLocation( const ::com::sun::star::uno::Any& rbase, const ::com::sun::star::uno::Any& rUrl );
72 : :
73 : : // ----------------------------------------------------
74 : : // class TabPageModel
75 : : // ----------------------------------------------------
76 : :
77 : : //TabPageModel::TabPageModel()
78 : : //{
79 : : //}
80 : : //TabPageModel::TabPageModel( uno::Reference< uno::XComponentContext > const & xCompContext)
81 : : //{
82 : : // (void) xCompContext;
83 : : //}
84 : : //
85 : : //TabPageModel::~TabPageModel()
86 : : //{
87 : : //}
88 : : //
89 : : //////----- XInitialization -------------------------------------------------------------------
90 : : //void SAL_CALL TabPageModel::initialize (const Sequence<Any>& rArguments)
91 : : //{
92 : : // sal_Int16 nPageId;
93 : : // if ( rArguments.getLength() == 1 )
94 : : // {
95 : : // if ( !( rArguments[ 0 ] >>= nPageId ))
96 : : // throw lang::IllegalArgumentException();
97 : : // m_nTabPageId = nPageId;
98 : : // }
99 : : // else
100 : : // m_nTabPageId = -1;
101 : : //}
102 : : //::sal_Int16 SAL_CALL TabPageModel::getTabPageID() throw (::com::sun::star::uno::RuntimeException)
103 : : //{
104 : : // return m_nTabPageId;
105 : : //}
106 : : //::sal_Bool SAL_CALL TabPageModel::getEnabled() throw (::com::sun::star::uno::RuntimeException)
107 : : //{
108 : : // return m_bEnabled;
109 : : //}
110 : : //void SAL_CALL TabPageModel::setEnabled( ::sal_Bool _enabled ) throw (::com::sun::star::uno::RuntimeException)
111 : : //{
112 : : // m_bEnabled = _enabled;
113 : : //}
114 : : //::rtl::OUString SAL_CALL TabPageModel::getTitle() throw (::com::sun::star::uno::RuntimeException)
115 : : //{
116 : : // return m_sTitle;
117 : : //}
118 : : //void SAL_CALL TabPageModel::setTitle( const ::rtl::OUString& _title ) throw (::com::sun::star::uno::RuntimeException)
119 : : //{
120 : : // m_sTitle = _title;
121 : : //}
122 : : //::rtl::OUString SAL_CALL TabPageModel::getImageURL() throw (::com::sun::star::uno::RuntimeException)
123 : : //{
124 : : // return m_sImageURL;
125 : : //}
126 : : //void SAL_CALL TabPageModel::setImageURL( const ::rtl::OUString& _imageurl ) throw (::com::sun::star::uno::RuntimeException)
127 : : //{
128 : : // m_sImageURL = _imageurl;
129 : : //}
130 : : //::rtl::OUString SAL_CALL TabPageModel::getTooltip() throw (::com::sun::star::uno::RuntimeException)
131 : : //{
132 : : // return m_sTooltip;
133 : : //}
134 : : //void SAL_CALL TabPageModel::setTooltip( const ::rtl::OUString& _tooltip ) throw (::com::sun::star::uno::RuntimeException)
135 : : //{
136 : : // m_sTooltip = _tooltip;
137 : : //}
138 : :
139 : : // ----------------------------------------------------
140 : : // class UnoControlTabPageModel
141 : : // ----------------------------------------------------
142 : 2 : UnoControlTabPageModel::UnoControlTabPageModel( Reference< XMultiServiceFactory > const & i_factory )
143 : 2 : :ControlModelContainerBase( i_factory )
144 : : {
145 [ + - ]: 2 : ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL );
146 [ + - ]: 2 : ImplRegisterProperty( BASEPROPERTY_TITLE );
147 [ + - ]: 2 : ImplRegisterProperty( BASEPROPERTY_HELPTEXT );
148 [ + - ]: 2 : ImplRegisterProperty( BASEPROPERTY_HELPURL );
149 [ + - ]: 2 : ImplRegisterProperty( BASEPROPERTY_IMAGEURL );
150 [ + - ]: 2 : ImplRegisterProperty( BASEPROPERTY_ENABLED );
151 : 2 : }
152 : :
153 : 0 : ::rtl::OUString UnoControlTabPageModel::getServiceName( ) throw(RuntimeException)
154 : : {
155 : 0 : return ::rtl::OUString::createFromAscii( szServiceName_UnoControlTabPageModel );
156 : : }
157 : :
158 : 12 : Any UnoControlTabPageModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
159 : : {
160 : 12 : Any aAny;
161 : :
162 [ + + ]: 12 : switch ( nPropId )
163 : : {
164 : : case BASEPROPERTY_DEFAULTCONTROL:
165 [ + - ]: 2 : aAny <<= ::rtl::OUString::createFromAscii( szServiceName_UnoControlTabPage );
166 : 2 : break;
167 : : default:
168 [ + - ]: 10 : aAny = UnoControlModel::ImplGetDefaultValue( nPropId );
169 : : }
170 : :
171 : 12 : return aAny;
172 : : }
173 : :
174 : 2 : ::cppu::IPropertyArrayHelper& UnoControlTabPageModel::getInfoHelper()
175 : : {
176 : : static UnoPropertyArrayHelper* pHelper = NULL;
177 [ + - ]: 2 : if ( !pHelper )
178 : : {
179 [ + - ]: 2 : Sequence<sal_Int32> aIDs = ImplGetPropertyIds();
180 [ + - ][ + - ]: 2 : pHelper = new UnoPropertyArrayHelper( aIDs );
181 : : }
182 : 2 : return *pHelper;
183 : : }
184 : : // beans::XMultiPropertySet
185 : 2 : uno::Reference< beans::XPropertySetInfo > UnoControlTabPageModel::getPropertySetInfo( ) throw(uno::RuntimeException)
186 : : {
187 [ + - ][ + - ]: 2 : static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
[ + - ][ + - ]
[ # # ]
188 : 2 : return xInfo;
189 : : }
190 : : ////----- XInitialization -------------------------------------------------------------------
191 : 0 : void SAL_CALL UnoControlTabPageModel::initialize (const Sequence<Any>& rArguments)
192 : : throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException)
193 : : {
194 : 0 : sal_Int16 nPageId = -1;
195 [ # # ]: 0 : if ( rArguments.getLength() == 1 )
196 : : {
197 [ # # ]: 0 : if ( !( rArguments[ 0 ] >>= nPageId ))
198 [ # # ]: 0 : throw lang::IllegalArgumentException();
199 : 0 : m_nTabPageId = nPageId;
200 : : }
201 [ # # ]: 0 : else if ( rArguments.getLength() == 2 )
202 : : {
203 [ # # ]: 0 : if ( !( rArguments[ 0 ] >>= nPageId ))
204 [ # # ]: 0 : throw lang::IllegalArgumentException();
205 : 0 : m_nTabPageId = nPageId;
206 : 0 : ::rtl::OUString sURL;
207 [ # # ]: 0 : if ( !( rArguments[ 1 ] >>= sURL ))
208 [ # # ]: 0 : throw lang::IllegalArgumentException();
209 [ # # ][ # # ]: 0 : Reference<container::XNameContainer > xDialogModel = awt::UnoControlDialogModelProvider::create( maContext.getUNOContext(),sURL);
210 [ # # ]: 0 : if ( xDialogModel.is() )
211 : : {
212 [ # # ][ # # ]: 0 : Sequence< ::rtl::OUString> aNames = xDialogModel->getElementNames();
213 : 0 : const ::rtl::OUString* pIter = aNames.getConstArray();
214 : 0 : const ::rtl::OUString* pEnd = pIter + aNames.getLength();
215 [ # # ]: 0 : for(;pIter != pEnd;++pIter)
216 : : {
217 : : try
218 : : {
219 [ # # ][ # # ]: 0 : Any aElement(xDialogModel->getByName(*pIter));
220 [ # # ][ # # ]: 0 : xDialogModel->removeByName(*pIter);
221 [ # # ][ # # ]: 0 : insertByName(*pIter,aElement);
222 : : }
223 [ # # ]: 0 : catch(const Exception& ex)
224 : : {
225 : : (void)ex;
226 : : }
227 : : }
228 [ # # ]: 0 : Reference<XPropertySet> xDialogProp(xDialogModel,UNO_QUERY);
229 [ # # ]: 0 : if ( xDialogProp.is() )
230 : : {
231 [ # # ][ # # ]: 0 : static const ::rtl::OUString s_sResourceResolver(RTL_CONSTASCII_USTRINGPARAM("ResourceResolver"));
[ # # ][ # # ]
232 [ # # ][ # # ]: 0 : Reference<XPropertySet> xThis(*this,UNO_QUERY);
233 [ # # ][ # # ]: 0 : xThis->setPropertyValue(s_sResourceResolver,xDialogProp->getPropertyValue(s_sResourceResolver));
[ # # ][ # # ]
234 [ # # ][ # # ]: 0 : xThis->setPropertyValue(GetPropertyName(BASEPROPERTY_TITLE),xDialogProp->getPropertyValue(GetPropertyName(BASEPROPERTY_TITLE)));
[ # # ][ # # ]
[ # # ][ # # ]
235 [ # # ][ # # ]: 0 : xThis->setPropertyValue(GetPropertyName(BASEPROPERTY_IMAGEURL),xDialogProp->getPropertyValue(GetPropertyName(BASEPROPERTY_IMAGEURL)));
[ # # ][ # # ]
[ # # ][ # # ]
236 [ # # ][ # # ]: 0 : xThis->setPropertyValue(GetPropertyName(BASEPROPERTY_HELPTEXT),xDialogProp->getPropertyValue(GetPropertyName(BASEPROPERTY_HELPTEXT)));
[ # # ][ # # ]
[ # # ][ # # ]
237 [ # # ][ # # ]: 0 : xThis->setPropertyValue(GetPropertyName(BASEPROPERTY_ENABLED),xDialogProp->getPropertyValue(GetPropertyName(BASEPROPERTY_ENABLED)));
[ # # ][ # # ]
[ # # ][ # # ]
238 [ # # ][ # # ]: 0 : xThis->setPropertyValue(GetPropertyName(BASEPROPERTY_HELPURL),xDialogProp->getPropertyValue(GetPropertyName(BASEPROPERTY_HELPURL)));
[ # # ][ # # ]
[ # # ][ # # ]
239 [ # # ]: 0 : }
240 : 0 : }
241 : : }
242 : : else
243 : 0 : m_nTabPageId = -1;
244 : 0 : }
245 : : //===== Service ===============================================================
246 : 0 : ::rtl::OUString UnoControlTabPageModel_getImplementationName (void) throw(RuntimeException)
247 : : {
248 : 0 : return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.tab.UnoControlTabPageModel"));
249 : : }
250 : :
251 : 0 : Sequence<rtl::OUString> SAL_CALL UnoControlTabPageModel_getSupportedServiceNames (void)
252 : : throw (RuntimeException)
253 : : {
254 [ # # ]: 0 : const ::rtl::OUString sServiceName(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.tab.UnoControlTabPageModel"));
255 [ # # ]: 0 : return Sequence<rtl::OUString>(&sServiceName, 1);
256 : : }
257 : : //=============================================================================
258 : : // = class UnoControlTabPage
259 : : // ============================================================================
260 : :
261 : 0 : UnoControlTabPage::UnoControlTabPage( const Reference< XMultiServiceFactory >& i_factory )
262 : : :UnoControlTabPage_Base( i_factory )
263 : 0 : ,m_bWindowListener(false)
264 : : {
265 : 0 : maComponentInfos.nWidth = 280;
266 : 0 : maComponentInfos.nHeight = 400;
267 : 0 : }
268 : 0 : UnoControlTabPage::~UnoControlTabPage()
269 : : {
270 [ # # ]: 0 : }
271 : :
272 : 0 : ::rtl::OUString UnoControlTabPage::GetComponentServiceName()
273 : : {
274 : 0 : return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TabPageModel"));
275 : : }
276 : :
277 : 0 : void UnoControlTabPage::dispose() throw(RuntimeException)
278 : : {
279 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
280 : :
281 [ # # ]: 0 : EventObject aEvt;
282 [ # # ]: 0 : aEvt.Source = static_cast< ::cppu::OWeakObject* >( this );
283 [ # # ][ # # ]: 0 : ControlContainerBase::dispose();
[ # # ]
284 : 0 : }
285 : :
286 : 0 : void SAL_CALL UnoControlTabPage::disposing( const EventObject& Source )throw(RuntimeException)
287 : : {
288 : 0 : ControlContainerBase::disposing( Source );
289 : 0 : }
290 : :
291 : 0 : void UnoControlTabPage::createPeer( const Reference< XToolkit > & rxToolkit, const Reference< XWindowPeer > & rParentPeer ) throw(RuntimeException)
292 : : {
293 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
294 [ # # ]: 0 : ImplUpdateResourceResolver();
295 : :
296 [ # # ]: 0 : UnoControlContainer::createPeer( rxToolkit, rParentPeer );
297 : :
298 [ # # ][ # # ]: 0 : Reference < tab::XTabPage > xTabPage( getPeer(), UNO_QUERY );
299 [ # # ]: 0 : if ( xTabPage.is() )
300 : : {
301 [ # # ]: 0 : if ( !m_bWindowListener )
302 : : {
303 [ # # ]: 0 : Reference< XWindowListener > xWL( static_cast< cppu::OWeakObject*>( this ), UNO_QUERY );
304 [ # # ]: 0 : addWindowListener( xWL );
305 : 0 : m_bWindowListener = true;
306 : : }
307 [ # # ]: 0 : }
308 : 0 : }
309 : :
310 : 0 : static ::Size ImplMapPixelToAppFont( OutputDevice* pOutDev, const ::Size& aSize )
311 : : {
312 [ # # ]: 0 : ::Size aTmp = pOutDev->PixelToLogic( aSize, MAP_APPFONT );
313 : 0 : return aTmp;
314 : : }
315 : : // ::com::sun::star::awt::XWindowListener
316 : 0 : void SAL_CALL UnoControlTabPage::windowResized( const ::com::sun::star::awt::WindowEvent& e )
317 : : throw (::com::sun::star::uno::RuntimeException)
318 : : {
319 : 0 : OutputDevice*pOutDev = Application::GetDefaultDevice();
320 : : DBG_ASSERT( pOutDev, "Missing Default Device!" );
321 [ # # ][ # # ]: 0 : if ( pOutDev && !mbSizeModified )
322 : : {
323 : : // Currentley we are simply using MAP_APPFONT
324 : 0 : ::Size aAppFontSize( e.Width, e.Height );
325 : :
326 [ # # ][ # # ]: 0 : Reference< XControl > xDialogControl( *this, UNO_QUERY_THROW );
327 [ # # ][ # # ]: 0 : Reference< XDevice > xDialogDevice( xDialogControl->getPeer(), UNO_QUERY );
[ # # ]
328 : : OSL_ENSURE( xDialogDevice.is(), "UnoDialogControl::windowResized: no peer, but a windowResized event?" );
329 [ # # ]: 0 : if ( xDialogDevice.is() )
330 : : {
331 [ # # ][ # # ]: 0 : DeviceInfo aDeviceInfo( xDialogDevice->getInfo() );
332 : 0 : aAppFontSize.Width() -= aDeviceInfo.LeftInset + aDeviceInfo.RightInset;
333 : 0 : aAppFontSize.Height() -= aDeviceInfo.TopInset + aDeviceInfo.BottomInset;
334 : : }
335 : :
336 [ # # ]: 0 : aAppFontSize = ImplMapPixelToAppFont( pOutDev, aAppFontSize );
337 : :
338 : : // Remember that changes have been done by listener. No need to
339 : : // update the position because of property change event.
340 : 0 : mbSizeModified = true;
341 [ # # ]: 0 : Sequence< rtl::OUString > aProps( 2 );
342 [ # # ]: 0 : Sequence< Any > aValues( 2 );
343 : : // Properties in a sequence must be sorted!
344 [ # # ][ # # ]: 0 : aProps[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Height" ));
345 [ # # ][ # # ]: 0 : aProps[1] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Width" ));
346 [ # # ][ # # ]: 0 : aValues[0] <<= aAppFontSize.Height();
347 [ # # ][ # # ]: 0 : aValues[1] <<= aAppFontSize.Width();
348 : :
349 [ # # ]: 0 : ImplSetPropertyValues( aProps, aValues, true );
350 [ # # ][ # # ]: 0 : mbSizeModified = false;
351 : : }
352 : 0 : }
353 : :
354 : 0 : void SAL_CALL UnoControlTabPage::windowMoved( const ::com::sun::star::awt::WindowEvent& e )
355 : : throw (::com::sun::star::uno::RuntimeException)
356 : : {
357 : 0 : OutputDevice*pOutDev = Application::GetDefaultDevice();
358 : : DBG_ASSERT( pOutDev, "Missing Default Device!" );
359 [ # # ][ # # ]: 0 : if ( pOutDev && !mbPosModified )
360 : : {
361 : : // Currentley we are simply using MAP_APPFONT
362 : 0 : Any aAny;
363 : 0 : ::Size aTmp( e.X, e.Y );
364 [ # # ]: 0 : aTmp = ImplMapPixelToAppFont( pOutDev, aTmp );
365 : :
366 : : // Remember that changes have been done by listener. No need to
367 : : // update the position because of property change event.
368 : 0 : mbPosModified = true;
369 [ # # ]: 0 : Sequence< rtl::OUString > aProps( 2 );
370 [ # # ]: 0 : Sequence< Any > aValues( 2 );
371 [ # # ][ # # ]: 0 : aProps[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PositionX" ));
372 [ # # ][ # # ]: 0 : aProps[1] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PositionY" ));
373 [ # # ][ # # ]: 0 : aValues[0] <<= aTmp.Width();
374 [ # # ][ # # ]: 0 : aValues[1] <<= aTmp.Height();
375 : :
376 [ # # ]: 0 : ImplSetPropertyValues( aProps, aValues, true );
377 [ # # ][ # # ]: 0 : mbPosModified = false;
378 : : }
379 : 0 : }
380 : :
381 : 0 : void SAL_CALL UnoControlTabPage::windowShown( const ::com::sun::star::lang::EventObject& e )
382 : : throw (::com::sun::star::uno::RuntimeException)
383 : : {
384 : : (void)e;
385 : 0 : }
386 : :
387 : 0 : void SAL_CALL UnoControlTabPage::windowHidden( const ::com::sun::star::lang::EventObject& e )
388 : : throw (::com::sun::star::uno::RuntimeException)
389 : : {
390 : : (void)e;
391 : 0 : }
392 : :
393 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|