1*b0724fc6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*b0724fc6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*b0724fc6SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*b0724fc6SAndrew Rist * distributed with this work for additional information
6*b0724fc6SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*b0724fc6SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*b0724fc6SAndrew Rist * "License"); you may not use this file except in compliance
9*b0724fc6SAndrew Rist * with the License. You may obtain a copy of the License at
10*b0724fc6SAndrew Rist *
11*b0724fc6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*b0724fc6SAndrew Rist *
13*b0724fc6SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*b0724fc6SAndrew Rist * software distributed under the License is distributed on an
15*b0724fc6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b0724fc6SAndrew Rist * KIND, either express or implied. See the License for the
17*b0724fc6SAndrew Rist * specific language governing permissions and limitations
18*b0724fc6SAndrew Rist * under the License.
19*b0724fc6SAndrew Rist *
20*b0724fc6SAndrew Rist *************************************************************/
21*b0724fc6SAndrew Rist
22*b0724fc6SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_toolkit.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <vcl/svapp.hxx>
28cdf0e10cSrcweir #include <vcl/window.hxx>
29cdf0e10cSrcweir #include <vcl/wall.hxx>
30cdf0e10cSrcweir #include <vos/mutex.hxx>
31cdf0e10cSrcweir #include <toolkit/controls/tabpagemodel.hxx>
32cdf0e10cSrcweir #include <toolkit/helper/property.hxx>
33cdf0e10cSrcweir #include <toolkit/helper/unopropertyarrayhelper.hxx>
34cdf0e10cSrcweir #include <toolkit/controls/stdtabcontroller.hxx>
35cdf0e10cSrcweir #include <com/sun/star/awt/PosSize.hpp>
36cdf0e10cSrcweir #include <com/sun/star/awt/WindowAttribute.hpp>
37cdf0e10cSrcweir #include <com/sun/star/awt/UnoControlDialogModelProvider.hpp>
38cdf0e10cSrcweir #include <com/sun/star/resource/XStringResourceResolver.hpp>
39cdf0e10cSrcweir #include <com/sun/star/graphic/XGraphicProvider.hpp>
40cdf0e10cSrcweir #include <tools/list.hxx>
41cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
42cdf0e10cSrcweir #include <tools/debug.hxx>
43cdf0e10cSrcweir #include <tools/diagnose_ex.h>
44cdf0e10cSrcweir #include <comphelper/sequence.hxx>
45cdf0e10cSrcweir #include <vcl/svapp.hxx>
46cdf0e10cSrcweir #include <vcl/outdev.hxx>
47cdf0e10cSrcweir
48cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
49cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx>
50cdf0e10cSrcweir #include <vcl/graph.hxx>
51cdf0e10cSrcweir #include <vcl/image.hxx>
52cdf0e10cSrcweir #include <toolkit/controls/geometrycontrolmodel.hxx>
53cdf0e10cSrcweir
54cdf0e10cSrcweir #include <map>
55cdf0e10cSrcweir #include <algorithm>
56cdf0e10cSrcweir #include <functional>
57cdf0e10cSrcweir #include "tools/urlobj.hxx"
58cdf0e10cSrcweir #include "osl/file.hxx"
59cdf0e10cSrcweir
60cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
61cdf0e10cSrcweir
62cdf0e10cSrcweir using namespace ::com::sun::star;
63cdf0e10cSrcweir using namespace ::com::sun::star::uno;
64cdf0e10cSrcweir using namespace ::com::sun::star::awt;
65cdf0e10cSrcweir using namespace ::com::sun::star::lang;
66cdf0e10cSrcweir using namespace ::com::sun::star::container;
67cdf0e10cSrcweir using namespace ::com::sun::star::beans;
68cdf0e10cSrcweir using namespace ::com::sun::star::util;
69cdf0e10cSrcweir
70cdf0e10cSrcweir ////HELPER
71cdf0e10cSrcweir ::rtl::OUString getPhysicalLocation( const ::com::sun::star::uno::Any& rbase, const ::com::sun::star::uno::Any& rUrl );
72cdf0e10cSrcweir
73cdf0e10cSrcweir // ----------------------------------------------------
74cdf0e10cSrcweir // class UnoControlTabPageModel
75cdf0e10cSrcweir // ----------------------------------------------------
UnoControlTabPageModel(Reference<XMultiServiceFactory> const & i_factory)76cdf0e10cSrcweir UnoControlTabPageModel::UnoControlTabPageModel( Reference< XMultiServiceFactory > const & i_factory )
77cdf0e10cSrcweir :ControlModelContainerBase( i_factory )
78cdf0e10cSrcweir {
79cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL );
80cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_TITLE );
81cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_HELPTEXT );
82cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_HELPURL );
83cdf0e10cSrcweir }
84cdf0e10cSrcweir
getServiceName()85cdf0e10cSrcweir ::rtl::OUString UnoControlTabPageModel::getServiceName( ) throw(RuntimeException)
86cdf0e10cSrcweir {
87cdf0e10cSrcweir return ::rtl::OUString::createFromAscii( szServiceName_UnoControlTabPageModel );
88cdf0e10cSrcweir }
89cdf0e10cSrcweir
ImplGetDefaultValue(sal_uInt16 nPropId) const90cdf0e10cSrcweir Any UnoControlTabPageModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
91cdf0e10cSrcweir {
92cdf0e10cSrcweir Any aAny;
93cdf0e10cSrcweir
94cdf0e10cSrcweir switch ( nPropId )
95cdf0e10cSrcweir {
96cdf0e10cSrcweir case BASEPROPERTY_DEFAULTCONTROL:
97cdf0e10cSrcweir aAny <<= ::rtl::OUString::createFromAscii( szServiceName_UnoControlTabPage );
98cdf0e10cSrcweir break;
99cdf0e10cSrcweir default:
100cdf0e10cSrcweir aAny = UnoControlModel::ImplGetDefaultValue( nPropId );
101cdf0e10cSrcweir }
102cdf0e10cSrcweir
103cdf0e10cSrcweir return aAny;
104cdf0e10cSrcweir }
105cdf0e10cSrcweir
getInfoHelper()106cdf0e10cSrcweir ::cppu::IPropertyArrayHelper& UnoControlTabPageModel::getInfoHelper()
107cdf0e10cSrcweir {
108cdf0e10cSrcweir static UnoPropertyArrayHelper* pHelper = NULL;
109cdf0e10cSrcweir if ( !pHelper )
110cdf0e10cSrcweir {
111cdf0e10cSrcweir Sequence<sal_Int32> aIDs = ImplGetPropertyIds();
112cdf0e10cSrcweir pHelper = new UnoPropertyArrayHelper( aIDs );
113cdf0e10cSrcweir }
114cdf0e10cSrcweir return *pHelper;
115cdf0e10cSrcweir }
116cdf0e10cSrcweir // beans::XMultiPropertySet
getPropertySetInfo()117cdf0e10cSrcweir uno::Reference< beans::XPropertySetInfo > UnoControlTabPageModel::getPropertySetInfo( ) throw(uno::RuntimeException)
118cdf0e10cSrcweir {
119cdf0e10cSrcweir static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
120cdf0e10cSrcweir return xInfo;
121cdf0e10cSrcweir }
122cdf0e10cSrcweir ////----- XInitialization -------------------------------------------------------------------
initialize(const Sequence<Any> & rArguments)123cdf0e10cSrcweir void SAL_CALL UnoControlTabPageModel::initialize (const Sequence<Any>& rArguments)
124cdf0e10cSrcweir throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException)
125cdf0e10cSrcweir {
126cdf0e10cSrcweir sal_Int16 nPageId = -1;
127cdf0e10cSrcweir if ( rArguments.getLength() == 1 )
128cdf0e10cSrcweir {
129cdf0e10cSrcweir if ( !( rArguments[ 0 ] >>= nPageId ))
130cdf0e10cSrcweir throw lang::IllegalArgumentException();
131cdf0e10cSrcweir m_nTabPageId = nPageId;
132cdf0e10cSrcweir }
133cdf0e10cSrcweir else if ( rArguments.getLength() == 2 )
134cdf0e10cSrcweir {
135cdf0e10cSrcweir if ( !( rArguments[ 0 ] >>= nPageId ))
136cdf0e10cSrcweir throw lang::IllegalArgumentException();
137cdf0e10cSrcweir m_nTabPageId = nPageId;
138cdf0e10cSrcweir ::rtl::OUString sURL;
139cdf0e10cSrcweir if ( !( rArguments[ 1 ] >>= sURL ))
140cdf0e10cSrcweir throw lang::IllegalArgumentException();
141cdf0e10cSrcweir Reference<container::XNameContainer > xDialogModel = awt::UnoControlDialogModelProvider::create( maContext.getUNOContext(),sURL);
142cdf0e10cSrcweir if ( xDialogModel.is() )
143cdf0e10cSrcweir {
144cdf0e10cSrcweir Sequence< ::rtl::OUString> aNames = xDialogModel->getElementNames();
145cdf0e10cSrcweir const ::rtl::OUString* pIter = aNames.getConstArray();
146cdf0e10cSrcweir const ::rtl::OUString* pEnd = pIter + aNames.getLength();
147cdf0e10cSrcweir for(;pIter != pEnd;++pIter)
148cdf0e10cSrcweir {
149cdf0e10cSrcweir try
150cdf0e10cSrcweir {
151cdf0e10cSrcweir Any aElement(xDialogModel->getByName(*pIter));
152cdf0e10cSrcweir xDialogModel->removeByName(*pIter);
153cdf0e10cSrcweir insertByName(*pIter,aElement);
154cdf0e10cSrcweir }
155cdf0e10cSrcweir catch(const Exception& ex)
156cdf0e10cSrcweir {
157cdf0e10cSrcweir (void)ex;
158cdf0e10cSrcweir }
159cdf0e10cSrcweir }
160cdf0e10cSrcweir Reference<XPropertySet> xDialogProp(xDialogModel,UNO_QUERY);
161cdf0e10cSrcweir if ( xDialogProp.is() )
162cdf0e10cSrcweir {
163cdf0e10cSrcweir static const ::rtl::OUString s_sResourceResolver(RTL_CONSTASCII_USTRINGPARAM("ResourceResolver"));
164cdf0e10cSrcweir Reference<XPropertySet> xThis(*this,UNO_QUERY);
165cdf0e10cSrcweir xThis->setPropertyValue(s_sResourceResolver,xDialogProp->getPropertyValue(s_sResourceResolver));
166cdf0e10cSrcweir xThis->setPropertyValue(GetPropertyName(BASEPROPERTY_TITLE),xDialogProp->getPropertyValue(GetPropertyName(BASEPROPERTY_TITLE)));
167cdf0e10cSrcweir xThis->setPropertyValue(GetPropertyName(BASEPROPERTY_HELPTEXT),xDialogProp->getPropertyValue(GetPropertyName(BASEPROPERTY_HELPTEXT)));
168cdf0e10cSrcweir xThis->setPropertyValue(GetPropertyName(BASEPROPERTY_HELPURL),xDialogProp->getPropertyValue(GetPropertyName(BASEPROPERTY_HELPURL)));
169cdf0e10cSrcweir }
170cdf0e10cSrcweir }
171cdf0e10cSrcweir }
172cdf0e10cSrcweir else
173cdf0e10cSrcweir m_nTabPageId = -1;
174cdf0e10cSrcweir }
175cdf0e10cSrcweir //===== Service ===============================================================
UnoControlTabPageModel_getImplementationName(void)176cdf0e10cSrcweir ::rtl::OUString UnoControlTabPageModel_getImplementationName (void) throw(RuntimeException)
177cdf0e10cSrcweir {
178cdf0e10cSrcweir return rtl::OUString::createFromAscii("com.sun.star.awt.tab.UnoControlTabPageModel");
179cdf0e10cSrcweir }
180cdf0e10cSrcweir
UnoControlTabPageModel_getSupportedServiceNames(void)181cdf0e10cSrcweir Sequence<rtl::OUString> SAL_CALL UnoControlTabPageModel_getSupportedServiceNames (void)
182cdf0e10cSrcweir throw (RuntimeException)
183cdf0e10cSrcweir {
184cdf0e10cSrcweir static const ::rtl::OUString sServiceName(
185cdf0e10cSrcweir ::rtl::OUString::createFromAscii("com.sun.star.awt.tab.UnoControlTabPageModel"));
186cdf0e10cSrcweir return Sequence<rtl::OUString>(&sServiceName, 1);
187cdf0e10cSrcweir }
188cdf0e10cSrcweir //=============================================================================
189cdf0e10cSrcweir // = class UnoControlTabPage
190cdf0e10cSrcweir // ============================================================================
191cdf0e10cSrcweir
UnoControlTabPage(const Reference<XMultiServiceFactory> & i_factory)192cdf0e10cSrcweir UnoControlTabPage::UnoControlTabPage( const Reference< XMultiServiceFactory >& i_factory )
193cdf0e10cSrcweir :UnoControlTabPage_Base( i_factory )
194cdf0e10cSrcweir ,m_bWindowListener(false)
195cdf0e10cSrcweir {
196cdf0e10cSrcweir maComponentInfos.nWidth = 280;
197cdf0e10cSrcweir maComponentInfos.nHeight = 400;
198cdf0e10cSrcweir }
~UnoControlTabPage()199cdf0e10cSrcweir UnoControlTabPage::~UnoControlTabPage()
200cdf0e10cSrcweir {
201cdf0e10cSrcweir }
202cdf0e10cSrcweir
GetComponentServiceName()203cdf0e10cSrcweir ::rtl::OUString UnoControlTabPage::GetComponentServiceName()
204cdf0e10cSrcweir {
205cdf0e10cSrcweir return ::rtl::OUString::createFromAscii( "TabPageModel" );
206cdf0e10cSrcweir }
207cdf0e10cSrcweir
dispose()208cdf0e10cSrcweir void UnoControlTabPage::dispose() throw(RuntimeException)
209cdf0e10cSrcweir {
210cdf0e10cSrcweir vos::OGuard aSolarGuard( Application::GetSolarMutex() );
211cdf0e10cSrcweir
212cdf0e10cSrcweir EventObject aEvt;
213cdf0e10cSrcweir aEvt.Source = static_cast< ::cppu::OWeakObject* >( this );
214cdf0e10cSrcweir ControlContainerBase::dispose();
215cdf0e10cSrcweir }
216cdf0e10cSrcweir
disposing(const EventObject & Source)217cdf0e10cSrcweir void SAL_CALL UnoControlTabPage::disposing( const EventObject& Source )throw(RuntimeException)
218cdf0e10cSrcweir {
219cdf0e10cSrcweir ControlContainerBase::disposing( Source );
220cdf0e10cSrcweir }
221cdf0e10cSrcweir
createPeer(const Reference<XToolkit> & rxToolkit,const Reference<XWindowPeer> & rParentPeer)222cdf0e10cSrcweir void UnoControlTabPage::createPeer( const Reference< XToolkit > & rxToolkit, const Reference< XWindowPeer > & rParentPeer ) throw(RuntimeException)
223cdf0e10cSrcweir {
224cdf0e10cSrcweir vos::OGuard aSolarGuard( Application::GetSolarMutex() );
225cdf0e10cSrcweir ImplUpdateResourceResolver();
226cdf0e10cSrcweir
227cdf0e10cSrcweir UnoControlContainer::createPeer( rxToolkit, rParentPeer );
228cdf0e10cSrcweir
229cdf0e10cSrcweir Reference < tab::XTabPage > xTabPage( getPeer(), UNO_QUERY );
230cdf0e10cSrcweir if ( xTabPage.is() )
231cdf0e10cSrcweir {
232cdf0e10cSrcweir if ( !m_bWindowListener )
233cdf0e10cSrcweir {
234cdf0e10cSrcweir Reference< XWindowListener > xWL( static_cast< cppu::OWeakObject*>( this ), UNO_QUERY );
235cdf0e10cSrcweir addWindowListener( xWL );
236cdf0e10cSrcweir m_bWindowListener = true;
237cdf0e10cSrcweir }
238cdf0e10cSrcweir }
239cdf0e10cSrcweir }
240cdf0e10cSrcweir
ImplMapPixelToAppFont(OutputDevice * pOutDev,const::Size & aSize)241cdf0e10cSrcweir static ::Size ImplMapPixelToAppFont( OutputDevice* pOutDev, const ::Size& aSize )
242cdf0e10cSrcweir {
243cdf0e10cSrcweir ::Size aTmp = pOutDev->PixelToLogic( aSize, MAP_APPFONT );
244cdf0e10cSrcweir return aTmp;
245cdf0e10cSrcweir }
246cdf0e10cSrcweir // ::com::sun::star::awt::XWindowListener
windowResized(const::com::sun::star::awt::WindowEvent & e)247cdf0e10cSrcweir void SAL_CALL UnoControlTabPage::windowResized( const ::com::sun::star::awt::WindowEvent& e )
248cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
249cdf0e10cSrcweir {
250cdf0e10cSrcweir OutputDevice*pOutDev = Application::GetDefaultDevice();
251cdf0e10cSrcweir DBG_ASSERT( pOutDev, "Missing Default Device!" );
252cdf0e10cSrcweir if ( pOutDev && !mbSizeModified )
253cdf0e10cSrcweir {
254cdf0e10cSrcweir // Currentley we are simply using MAP_APPFONT
255cdf0e10cSrcweir ::Size aAppFontSize( e.Width, e.Height );
256cdf0e10cSrcweir
257cdf0e10cSrcweir Reference< XControl > xDialogControl( *this, UNO_QUERY_THROW );
258cdf0e10cSrcweir Reference< XDevice > xDialogDevice( xDialogControl->getPeer(), UNO_QUERY );
259cdf0e10cSrcweir OSL_ENSURE( xDialogDevice.is(), "UnoDialogControl::windowResized: no peer, but a windowResized event?" );
260cdf0e10cSrcweir if ( xDialogDevice.is() )
261cdf0e10cSrcweir {
262cdf0e10cSrcweir DeviceInfo aDeviceInfo( xDialogDevice->getInfo() );
263cdf0e10cSrcweir aAppFontSize.Width() -= aDeviceInfo.LeftInset + aDeviceInfo.RightInset;
264cdf0e10cSrcweir aAppFontSize.Height() -= aDeviceInfo.TopInset + aDeviceInfo.BottomInset;
265cdf0e10cSrcweir }
266cdf0e10cSrcweir
267cdf0e10cSrcweir aAppFontSize = ImplMapPixelToAppFont( pOutDev, aAppFontSize );
268cdf0e10cSrcweir
269cdf0e10cSrcweir // Remember that changes have been done by listener. No need to
270cdf0e10cSrcweir // update the position because of property change event.
271cdf0e10cSrcweir mbSizeModified = true;
272cdf0e10cSrcweir Sequence< rtl::OUString > aProps( 2 );
273cdf0e10cSrcweir Sequence< Any > aValues( 2 );
274cdf0e10cSrcweir // Properties in a sequence must be sorted!
275cdf0e10cSrcweir aProps[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Height" ));
276cdf0e10cSrcweir aProps[1] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Width" ));
277cdf0e10cSrcweir aValues[0] <<= aAppFontSize.Height();
278cdf0e10cSrcweir aValues[1] <<= aAppFontSize.Width();
279cdf0e10cSrcweir
280cdf0e10cSrcweir ImplSetPropertyValues( aProps, aValues, true );
281cdf0e10cSrcweir mbSizeModified = false;
282cdf0e10cSrcweir }
283cdf0e10cSrcweir }
284cdf0e10cSrcweir
windowMoved(const::com::sun::star::awt::WindowEvent & e)285cdf0e10cSrcweir void SAL_CALL UnoControlTabPage::windowMoved( const ::com::sun::star::awt::WindowEvent& e )
286cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
287cdf0e10cSrcweir {
288cdf0e10cSrcweir OutputDevice*pOutDev = Application::GetDefaultDevice();
289cdf0e10cSrcweir DBG_ASSERT( pOutDev, "Missing Default Device!" );
290cdf0e10cSrcweir if ( pOutDev && !mbPosModified )
291cdf0e10cSrcweir {
292cdf0e10cSrcweir // Currentley we are simply using MAP_APPFONT
293cdf0e10cSrcweir Any aAny;
294cdf0e10cSrcweir ::Size aTmp( e.X, e.Y );
295cdf0e10cSrcweir aTmp = ImplMapPixelToAppFont( pOutDev, aTmp );
296cdf0e10cSrcweir
297cdf0e10cSrcweir // Remember that changes have been done by listener. No need to
298cdf0e10cSrcweir // update the position because of property change event.
299cdf0e10cSrcweir mbPosModified = true;
300cdf0e10cSrcweir Sequence< rtl::OUString > aProps( 2 );
301cdf0e10cSrcweir Sequence< Any > aValues( 2 );
302cdf0e10cSrcweir aProps[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PositionX" ));
303cdf0e10cSrcweir aProps[1] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PositionY" ));
304cdf0e10cSrcweir aValues[0] <<= aTmp.Width();
305cdf0e10cSrcweir aValues[1] <<= aTmp.Height();
306cdf0e10cSrcweir
307cdf0e10cSrcweir ImplSetPropertyValues( aProps, aValues, true );
308cdf0e10cSrcweir mbPosModified = false;
309cdf0e10cSrcweir }
310cdf0e10cSrcweir }
311cdf0e10cSrcweir
windowShown(const::com::sun::star::lang::EventObject & e)312cdf0e10cSrcweir void SAL_CALL UnoControlTabPage::windowShown( const ::com::sun::star::lang::EventObject& e )
313cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
314cdf0e10cSrcweir {
315cdf0e10cSrcweir (void)e;
316cdf0e10cSrcweir }
317cdf0e10cSrcweir
windowHidden(const::com::sun::star::lang::EventObject & e)318cdf0e10cSrcweir void SAL_CALL UnoControlTabPage::windowHidden( const ::com::sun::star::lang::EventObject& e )
319cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
320cdf0e10cSrcweir {
321cdf0e10cSrcweir (void)e;
322cdf0e10cSrcweir }
323