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