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