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 10cdf0e10cSrcweir * 11*b0724fc6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 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. 19cdf0e10cSrcweir * 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 // ---------------------------------------------------- 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 ImplRegisterProperty( BASEPROPERTY_IMAGEURL ); 84cdf0e10cSrcweir ImplRegisterProperty( BASEPROPERTY_ENABLED ); 85cdf0e10cSrcweir } 86cdf0e10cSrcweir 87cdf0e10cSrcweir ::rtl::OUString UnoControlTabPageModel::getServiceName( ) throw(RuntimeException) 88cdf0e10cSrcweir { 89cdf0e10cSrcweir return ::rtl::OUString::createFromAscii( szServiceName_UnoControlTabPageModel ); 90cdf0e10cSrcweir } 91cdf0e10cSrcweir 92cdf0e10cSrcweir Any UnoControlTabPageModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const 93cdf0e10cSrcweir { 94cdf0e10cSrcweir Any aAny; 95cdf0e10cSrcweir 96cdf0e10cSrcweir switch ( nPropId ) 97cdf0e10cSrcweir { 98cdf0e10cSrcweir case BASEPROPERTY_DEFAULTCONTROL: 99cdf0e10cSrcweir aAny <<= ::rtl::OUString::createFromAscii( szServiceName_UnoControlTabPage ); 100cdf0e10cSrcweir break; 101cdf0e10cSrcweir default: 102cdf0e10cSrcweir aAny = UnoControlModel::ImplGetDefaultValue( nPropId ); 103cdf0e10cSrcweir } 104cdf0e10cSrcweir 105cdf0e10cSrcweir return aAny; 106cdf0e10cSrcweir } 107cdf0e10cSrcweir 108cdf0e10cSrcweir ::cppu::IPropertyArrayHelper& UnoControlTabPageModel::getInfoHelper() 109cdf0e10cSrcweir { 110cdf0e10cSrcweir static UnoPropertyArrayHelper* pHelper = NULL; 111cdf0e10cSrcweir if ( !pHelper ) 112cdf0e10cSrcweir { 113cdf0e10cSrcweir Sequence<sal_Int32> aIDs = ImplGetPropertyIds(); 114cdf0e10cSrcweir pHelper = new UnoPropertyArrayHelper( aIDs ); 115cdf0e10cSrcweir } 116cdf0e10cSrcweir return *pHelper; 117cdf0e10cSrcweir } 118cdf0e10cSrcweir // beans::XMultiPropertySet 119cdf0e10cSrcweir uno::Reference< beans::XPropertySetInfo > UnoControlTabPageModel::getPropertySetInfo( ) throw(uno::RuntimeException) 120cdf0e10cSrcweir { 121cdf0e10cSrcweir static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); 122cdf0e10cSrcweir return xInfo; 123cdf0e10cSrcweir } 124cdf0e10cSrcweir ////----- XInitialization ------------------------------------------------------------------- 125cdf0e10cSrcweir void SAL_CALL UnoControlTabPageModel::initialize (const Sequence<Any>& rArguments) 126cdf0e10cSrcweir throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException) 127cdf0e10cSrcweir { 128cdf0e10cSrcweir sal_Int16 nPageId = -1; 129cdf0e10cSrcweir if ( rArguments.getLength() == 1 ) 130cdf0e10cSrcweir { 131cdf0e10cSrcweir if ( !( rArguments[ 0 ] >>= nPageId )) 132cdf0e10cSrcweir throw lang::IllegalArgumentException(); 133cdf0e10cSrcweir m_nTabPageId = nPageId; 134cdf0e10cSrcweir } 135cdf0e10cSrcweir else if ( rArguments.getLength() == 2 ) 136cdf0e10cSrcweir { 137cdf0e10cSrcweir if ( !( rArguments[ 0 ] >>= nPageId )) 138cdf0e10cSrcweir throw lang::IllegalArgumentException(); 139cdf0e10cSrcweir m_nTabPageId = nPageId; 140cdf0e10cSrcweir ::rtl::OUString sURL; 141cdf0e10cSrcweir if ( !( rArguments[ 1 ] >>= sURL )) 142cdf0e10cSrcweir throw lang::IllegalArgumentException(); 143cdf0e10cSrcweir Reference<container::XNameContainer > xDialogModel = awt::UnoControlDialogModelProvider::create( maContext.getUNOContext(),sURL); 144cdf0e10cSrcweir if ( xDialogModel.is() ) 145cdf0e10cSrcweir { 146cdf0e10cSrcweir Sequence< ::rtl::OUString> aNames = xDialogModel->getElementNames(); 147cdf0e10cSrcweir const ::rtl::OUString* pIter = aNames.getConstArray(); 148cdf0e10cSrcweir const ::rtl::OUString* pEnd = pIter + aNames.getLength(); 149cdf0e10cSrcweir for(;pIter != pEnd;++pIter) 150cdf0e10cSrcweir { 151cdf0e10cSrcweir try 152cdf0e10cSrcweir { 153cdf0e10cSrcweir Any aElement(xDialogModel->getByName(*pIter)); 154cdf0e10cSrcweir xDialogModel->removeByName(*pIter); 155cdf0e10cSrcweir insertByName(*pIter,aElement); 156cdf0e10cSrcweir } 157cdf0e10cSrcweir catch(const Exception& ex) 158cdf0e10cSrcweir { 159cdf0e10cSrcweir (void)ex; 160cdf0e10cSrcweir } 161cdf0e10cSrcweir } 162cdf0e10cSrcweir Reference<XPropertySet> xDialogProp(xDialogModel,UNO_QUERY); 163cdf0e10cSrcweir if ( xDialogProp.is() ) 164cdf0e10cSrcweir { 165cdf0e10cSrcweir static const ::rtl::OUString s_sResourceResolver(RTL_CONSTASCII_USTRINGPARAM("ResourceResolver")); 166cdf0e10cSrcweir Reference<XPropertySet> xThis(*this,UNO_QUERY); 167cdf0e10cSrcweir xThis->setPropertyValue(s_sResourceResolver,xDialogProp->getPropertyValue(s_sResourceResolver)); 168cdf0e10cSrcweir xThis->setPropertyValue(GetPropertyName(BASEPROPERTY_TITLE),xDialogProp->getPropertyValue(GetPropertyName(BASEPROPERTY_TITLE))); 169cdf0e10cSrcweir xThis->setPropertyValue(GetPropertyName(BASEPROPERTY_IMAGEURL),xDialogProp->getPropertyValue(GetPropertyName(BASEPROPERTY_IMAGEURL))); 170cdf0e10cSrcweir xThis->setPropertyValue(GetPropertyName(BASEPROPERTY_HELPTEXT),xDialogProp->getPropertyValue(GetPropertyName(BASEPROPERTY_HELPTEXT))); 171cdf0e10cSrcweir xThis->setPropertyValue(GetPropertyName(BASEPROPERTY_ENABLED),xDialogProp->getPropertyValue(GetPropertyName(BASEPROPERTY_ENABLED))); 172cdf0e10cSrcweir xThis->setPropertyValue(GetPropertyName(BASEPROPERTY_HELPURL),xDialogProp->getPropertyValue(GetPropertyName(BASEPROPERTY_HELPURL))); 173cdf0e10cSrcweir } 174cdf0e10cSrcweir } 175cdf0e10cSrcweir } 176cdf0e10cSrcweir else 177cdf0e10cSrcweir m_nTabPageId = -1; 178cdf0e10cSrcweir } 179cdf0e10cSrcweir //===== Service =============================================================== 180cdf0e10cSrcweir ::rtl::OUString UnoControlTabPageModel_getImplementationName (void) throw(RuntimeException) 181cdf0e10cSrcweir { 182cdf0e10cSrcweir return rtl::OUString::createFromAscii("com.sun.star.awt.tab.UnoControlTabPageModel"); 183cdf0e10cSrcweir } 184cdf0e10cSrcweir 185cdf0e10cSrcweir Sequence<rtl::OUString> SAL_CALL UnoControlTabPageModel_getSupportedServiceNames (void) 186cdf0e10cSrcweir throw (RuntimeException) 187cdf0e10cSrcweir { 188cdf0e10cSrcweir static const ::rtl::OUString sServiceName( 189cdf0e10cSrcweir ::rtl::OUString::createFromAscii("com.sun.star.awt.tab.UnoControlTabPageModel")); 190cdf0e10cSrcweir return Sequence<rtl::OUString>(&sServiceName, 1); 191cdf0e10cSrcweir } 192cdf0e10cSrcweir //============================================================================= 193cdf0e10cSrcweir // = class UnoControlTabPage 194cdf0e10cSrcweir // ============================================================================ 195cdf0e10cSrcweir 196cdf0e10cSrcweir UnoControlTabPage::UnoControlTabPage( const Reference< XMultiServiceFactory >& i_factory ) 197cdf0e10cSrcweir :UnoControlTabPage_Base( i_factory ) 198cdf0e10cSrcweir ,m_bWindowListener(false) 199cdf0e10cSrcweir { 200cdf0e10cSrcweir maComponentInfos.nWidth = 280; 201cdf0e10cSrcweir maComponentInfos.nHeight = 400; 202cdf0e10cSrcweir } 203cdf0e10cSrcweir UnoControlTabPage::~UnoControlTabPage() 204cdf0e10cSrcweir { 205cdf0e10cSrcweir } 206cdf0e10cSrcweir 207cdf0e10cSrcweir ::rtl::OUString UnoControlTabPage::GetComponentServiceName() 208cdf0e10cSrcweir { 209cdf0e10cSrcweir return ::rtl::OUString::createFromAscii( "TabPageModel" ); 210cdf0e10cSrcweir } 211cdf0e10cSrcweir 212cdf0e10cSrcweir void UnoControlTabPage::dispose() throw(RuntimeException) 213cdf0e10cSrcweir { 214cdf0e10cSrcweir vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 215cdf0e10cSrcweir 216cdf0e10cSrcweir EventObject aEvt; 217cdf0e10cSrcweir aEvt.Source = static_cast< ::cppu::OWeakObject* >( this ); 218cdf0e10cSrcweir ControlContainerBase::dispose(); 219cdf0e10cSrcweir } 220cdf0e10cSrcweir 221cdf0e10cSrcweir void SAL_CALL UnoControlTabPage::disposing( const EventObject& Source )throw(RuntimeException) 222cdf0e10cSrcweir { 223cdf0e10cSrcweir ControlContainerBase::disposing( Source ); 224cdf0e10cSrcweir } 225cdf0e10cSrcweir 226cdf0e10cSrcweir void UnoControlTabPage::createPeer( const Reference< XToolkit > & rxToolkit, const Reference< XWindowPeer > & rParentPeer ) throw(RuntimeException) 227cdf0e10cSrcweir { 228cdf0e10cSrcweir vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 229cdf0e10cSrcweir ImplUpdateResourceResolver(); 230cdf0e10cSrcweir 231cdf0e10cSrcweir UnoControlContainer::createPeer( rxToolkit, rParentPeer ); 232cdf0e10cSrcweir 233cdf0e10cSrcweir Reference < tab::XTabPage > xTabPage( getPeer(), UNO_QUERY ); 234cdf0e10cSrcweir if ( xTabPage.is() ) 235cdf0e10cSrcweir { 236cdf0e10cSrcweir if ( !m_bWindowListener ) 237cdf0e10cSrcweir { 238cdf0e10cSrcweir Reference< XWindowListener > xWL( static_cast< cppu::OWeakObject*>( this ), UNO_QUERY ); 239cdf0e10cSrcweir addWindowListener( xWL ); 240cdf0e10cSrcweir m_bWindowListener = true; 241cdf0e10cSrcweir } 242cdf0e10cSrcweir } 243cdf0e10cSrcweir } 244cdf0e10cSrcweir 245cdf0e10cSrcweir static ::Size ImplMapPixelToAppFont( OutputDevice* pOutDev, const ::Size& aSize ) 246cdf0e10cSrcweir { 247cdf0e10cSrcweir ::Size aTmp = pOutDev->PixelToLogic( aSize, MAP_APPFONT ); 248cdf0e10cSrcweir return aTmp; 249cdf0e10cSrcweir } 250cdf0e10cSrcweir // ::com::sun::star::awt::XWindowListener 251cdf0e10cSrcweir void SAL_CALL UnoControlTabPage::windowResized( const ::com::sun::star::awt::WindowEvent& e ) 252cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException) 253cdf0e10cSrcweir { 254cdf0e10cSrcweir OutputDevice*pOutDev = Application::GetDefaultDevice(); 255cdf0e10cSrcweir DBG_ASSERT( pOutDev, "Missing Default Device!" ); 256cdf0e10cSrcweir if ( pOutDev && !mbSizeModified ) 257cdf0e10cSrcweir { 258cdf0e10cSrcweir // Currentley we are simply using MAP_APPFONT 259cdf0e10cSrcweir ::Size aAppFontSize( e.Width, e.Height ); 260cdf0e10cSrcweir 261cdf0e10cSrcweir Reference< XControl > xDialogControl( *this, UNO_QUERY_THROW ); 262cdf0e10cSrcweir Reference< XDevice > xDialogDevice( xDialogControl->getPeer(), UNO_QUERY ); 263cdf0e10cSrcweir OSL_ENSURE( xDialogDevice.is(), "UnoDialogControl::windowResized: no peer, but a windowResized event?" ); 264cdf0e10cSrcweir if ( xDialogDevice.is() ) 265cdf0e10cSrcweir { 266cdf0e10cSrcweir DeviceInfo aDeviceInfo( xDialogDevice->getInfo() ); 267cdf0e10cSrcweir aAppFontSize.Width() -= aDeviceInfo.LeftInset + aDeviceInfo.RightInset; 268cdf0e10cSrcweir aAppFontSize.Height() -= aDeviceInfo.TopInset + aDeviceInfo.BottomInset; 269cdf0e10cSrcweir } 270cdf0e10cSrcweir 271cdf0e10cSrcweir aAppFontSize = ImplMapPixelToAppFont( pOutDev, aAppFontSize ); 272cdf0e10cSrcweir 273cdf0e10cSrcweir // Remember that changes have been done by listener. No need to 274cdf0e10cSrcweir // update the position because of property change event. 275cdf0e10cSrcweir mbSizeModified = true; 276cdf0e10cSrcweir Sequence< rtl::OUString > aProps( 2 ); 277cdf0e10cSrcweir Sequence< Any > aValues( 2 ); 278cdf0e10cSrcweir // Properties in a sequence must be sorted! 279cdf0e10cSrcweir aProps[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Height" )); 280cdf0e10cSrcweir aProps[1] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Width" )); 281cdf0e10cSrcweir aValues[0] <<= aAppFontSize.Height(); 282cdf0e10cSrcweir aValues[1] <<= aAppFontSize.Width(); 283cdf0e10cSrcweir 284cdf0e10cSrcweir ImplSetPropertyValues( aProps, aValues, true ); 285cdf0e10cSrcweir mbSizeModified = false; 286cdf0e10cSrcweir } 287cdf0e10cSrcweir } 288cdf0e10cSrcweir 289cdf0e10cSrcweir void SAL_CALL UnoControlTabPage::windowMoved( const ::com::sun::star::awt::WindowEvent& e ) 290cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException) 291cdf0e10cSrcweir { 292cdf0e10cSrcweir OutputDevice*pOutDev = Application::GetDefaultDevice(); 293cdf0e10cSrcweir DBG_ASSERT( pOutDev, "Missing Default Device!" ); 294cdf0e10cSrcweir if ( pOutDev && !mbPosModified ) 295cdf0e10cSrcweir { 296cdf0e10cSrcweir // Currentley we are simply using MAP_APPFONT 297cdf0e10cSrcweir Any aAny; 298cdf0e10cSrcweir ::Size aTmp( e.X, e.Y ); 299cdf0e10cSrcweir aTmp = ImplMapPixelToAppFont( pOutDev, aTmp ); 300cdf0e10cSrcweir 301cdf0e10cSrcweir // Remember that changes have been done by listener. No need to 302cdf0e10cSrcweir // update the position because of property change event. 303cdf0e10cSrcweir mbPosModified = true; 304cdf0e10cSrcweir Sequence< rtl::OUString > aProps( 2 ); 305cdf0e10cSrcweir Sequence< Any > aValues( 2 ); 306cdf0e10cSrcweir aProps[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PositionX" )); 307cdf0e10cSrcweir aProps[1] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PositionY" )); 308cdf0e10cSrcweir aValues[0] <<= aTmp.Width(); 309cdf0e10cSrcweir aValues[1] <<= aTmp.Height(); 310cdf0e10cSrcweir 311cdf0e10cSrcweir ImplSetPropertyValues( aProps, aValues, true ); 312cdf0e10cSrcweir mbPosModified = false; 313cdf0e10cSrcweir } 314cdf0e10cSrcweir } 315cdf0e10cSrcweir 316cdf0e10cSrcweir void SAL_CALL UnoControlTabPage::windowShown( const ::com::sun::star::lang::EventObject& e ) 317cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException) 318cdf0e10cSrcweir { 319cdf0e10cSrcweir (void)e; 320cdf0e10cSrcweir } 321cdf0e10cSrcweir 322cdf0e10cSrcweir void SAL_CALL UnoControlTabPage::windowHidden( const ::com::sun::star::lang::EventObject& e ) 323cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException) 324cdf0e10cSrcweir { 325cdf0e10cSrcweir (void)e; 326cdf0e10cSrcweir } 327