xref: /trunk/main/toolkit/source/controls/controlmodelcontainerbase.cxx (revision e8df90a080f9dc7518c4b937d7dcd461d7b4d178)
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 <toolkit/controls/controlmodelcontainerbase.hxx>
28 #include <vcl/svapp.hxx>
29 #include <vcl/window.hxx>
30 #include <vcl/wall.hxx>
31 #include <vos/mutex.hxx>
32 #include <toolkit/helper/property.hxx>
33 #include <toolkit/helper/unopropertyarrayhelper.hxx>
34 #include <toolkit/controls/geometrycontrolmodel.hxx>
35 #include <toolkit/controls/unocontrols.hxx>
36 #include "toolkit/controls/formattedcontrol.hxx"
37 #include "toolkit/controls/roadmapcontrol.hxx"
38 #include "toolkit/controls/tkscrollbar.hxx"
39 #include "toolkit/controls/tabpagemodel.hxx"
40 #include <toolkit/controls/stdtabcontroller.hxx>
41 #include <com/sun/star/awt/PosSize.hpp>
42 #include <com/sun/star/awt/WindowAttribute.hpp>
43 #include <com/sun/star/resource/XStringResourceResolver.hpp>
44 #include <com/sun/star/graphic/XGraphicProvider.hpp>
45 #include <com/sun/star/lang/XInitialization.hpp>
46 #include <tools/list.hxx>
47 #include <cppuhelper/typeprovider.hxx>
48 #include <tools/debug.hxx>
49 #include <tools/diagnose_ex.h>
50 #include <comphelper/processfactory.hxx>
51 #include <vcl/svapp.hxx>
52 #include <vcl/outdev.hxx>
53 #include <comphelper/types.hxx>
54 
55 #include <comphelper/componentcontext.hxx>
56 #include <toolkit/helper/vclunohelper.hxx>
57 #include <toolkit/helper/tkresmgr.hxx>
58 #include <unotools/ucbstreamhelper.hxx>
59 #include <vcl/graph.hxx>
60 #include <vcl/image.hxx>
61 
62 #include "tree/treecontrol.hxx"
63 #include "grid/gridcontrol.hxx"
64 #include <toolkit/controls/tabpagecontainer.hxx>
65 
66 #include <map>
67 #include <algorithm>
68 #include <functional>
69 #include "tools/urlobj.hxx"
70 #include "osl/file.hxx"
71 
72 using namespace ::com::sun::star;
73 using namespace ::com::sun::star::uno;
74 using namespace ::com::sun::star::awt;
75 using namespace ::com::sun::star::lang;
76 using namespace ::com::sun::star::container;
77 using namespace ::com::sun::star::beans;
78 using namespace ::com::sun::star::util;
79 using namespace toolkit;
80 
81 #define PROPERTY_RESOURCERESOLVER ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ResourceResolver" ))
82 
83 //HELPER
84 ::rtl::OUString getPhysicalLocation( const ::com::sun::star::uno::Any& rbase, const ::com::sun::star::uno::Any& rUrl );
85 
86 struct LanguageDependentProp
87 {
88     const char* pPropName;
89     sal_Int32   nPropNameLength;
90 };
91 
92 // ----------------------------------------------------------------------------
93 namespace
94 {
lcl_getLanguageDependentProperties()95     static const Sequence< ::rtl::OUString >& lcl_getLanguageDependentProperties()
96     {
97         static Sequence< ::rtl::OUString > s_aLanguageDependentProperties;
98         if ( s_aLanguageDependentProperties.getLength() == 0 )
99         {
100             ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
101             if ( s_aLanguageDependentProperties.getLength() == 0 )
102             {
103                 s_aLanguageDependentProperties.realloc( 2 );
104                 s_aLanguageDependentProperties[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HelpText" ) );
105                 s_aLanguageDependentProperties[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) );
106                 // note: properties must be sorted
107             }
108         }
109         return s_aLanguageDependentProperties;
110     }
111 }
112 
113 // ----------------------------------------------------------------------------
114 // functor for disposing a control model
115 struct DisposeControlModel
116 {
117     typedef Reference< XControlModel > argument_type;
118     typedef void result_type;
operator ()DisposeControlModel119     void operator()( Reference< XControlModel >& _rxModel )
120     {
121         try
122         {
123             ::comphelper::disposeComponent( _rxModel );
124         }
125         catch( const Exception& )
126         {
127             DBG_ERROR( "DisposeControlModel::(): caught an exception while disposing a component!" );
128         }
129     }
130 };
131 
132 // ----------------------------------------------------------------------------
133 // functor for searching control model by name
134 struct FindControlModel
135 {
136     typedef ControlModelContainerBase::UnoControlModelHolder argument_type;
137     typedef bool result_type;
138 private:
139     const ::rtl::OUString& m_rName;
140 
141 public:
FindControlModelFindControlModel142     FindControlModel( const ::rtl::OUString& _rName ) : m_rName( _rName ) { }
143 
operator ()FindControlModel144     bool operator()( const ControlModelContainerBase::UnoControlModelHolder& _rCompare )
145     {
146         return ( _rCompare.second == m_rName ) ? true : false;
147     }
148 };
149 
150 // ----------------------------------------------------------------------------
151 // functor for cloning a control model, and insertion into a target list
152 struct CloneControlModel
153 {
154     typedef ControlModelContainerBase::UnoControlModelHolder argument_type;
155     typedef void result_type;
156 private:
157     ControlModelContainerBase::UnoControlModelHolderList&   m_rTargetList;
158 
159 public:
CloneControlModelCloneControlModel160     CloneControlModel( ControlModelContainerBase::UnoControlModelHolderList& _rTargetList )
161         :m_rTargetList( _rTargetList )
162     {
163     }
164 
operator ()CloneControlModel165     void operator()( const ControlModelContainerBase::UnoControlModelHolder& _rSource )
166     {
167         // clone the source object
168         Reference< XCloneable > xCloneSource( _rSource.first, UNO_QUERY );
169         Reference< XControlModel > xClone( xCloneSource->createClone(), UNO_QUERY );
170         // add to target list
171         m_rTargetList.push_back( ControlModelContainerBase::UnoControlModelHolder( xClone, _rSource.second ) );
172     }
173 };
174 
175 // ----------------------------------------------------------------------------
176 // functor for comparing a XControlModel with a given reference
177 struct CompareControlModel
178 {
179     typedef ControlModelContainerBase::UnoControlModelHolder argument_type;
180     typedef bool result_type;
181 private:
182     Reference< XControlModel > m_xReference;
183 public:
CompareControlModelCompareControlModel184     CompareControlModel( const Reference< XControlModel >& _rxReference ) : m_xReference( _rxReference ) { }
185 
operator ()CompareControlModel186     bool operator()( const ControlModelContainerBase::UnoControlModelHolder& _rCompare )
187     {
188         return ( _rCompare.first.get() == m_xReference.get() ) ? true : false;
189     }
190 };
191 
192 // ----------------------------------------------------------------------------
lcl_throwIllegalArgumentException()193 static void lcl_throwIllegalArgumentException( )
194 {   // throwing is expensive (in terms of code size), thus we hope the compiler does not inline this ....
195     throw IllegalArgumentException();
196 }
197 
198 // ----------------------------------------------------------------------------
lcl_throwNoSuchElementException()199 static void lcl_throwNoSuchElementException( )
200 {   // throwing is expensive (in terms of code size), thus we hope the compiler does not inline this ....
201     throw NoSuchElementException();
202 }
203 
204 // ----------------------------------------------------------------------------
lcl_throwElementExistException()205 static void lcl_throwElementExistException( )
206 {   // throwing is expensive (in terms of code size), thus we hope the compiler does not inline this ....
207     throw ElementExistException();
208 }
209 
210 // ----------------------------------------------------------------------------
getTabIndexPropertyName()211 static const ::rtl::OUString& getTabIndexPropertyName( )
212 {
213     static const ::rtl::OUString s_sTabIndexProperty( RTL_CONSTASCII_USTRINGPARAM( "TabIndex" ) );
214     return s_sTabIndexProperty;
215 }
216 
217 // ----------------------------------------------------------------------------
getStepPropertyName()218 static const ::rtl::OUString& getStepPropertyName( )
219 {
220     static const ::rtl::OUString s_sStepProperty( RTL_CONSTASCII_USTRINGPARAM( "Step" ) );
221     return s_sStepProperty;
222 }
223 
224 //  ----------------------------------------------------
225 //  class ControlModelContainerBase
226 //  ----------------------------------------------------
ControlModelContainerBase(const Reference<XMultiServiceFactory> & i_factory)227 ControlModelContainerBase::ControlModelContainerBase( const Reference< XMultiServiceFactory >& i_factory )
228     :ControlModelContainer_IBase( i_factory )
229     ,maContainerListeners( *this )
230     ,maChangeListeners ( GetMutex() )
231     ,mbGroupsUpToDate( sal_False )
232     ,m_bEnabled( sal_True )
233 {
234 }
235 
ControlModelContainerBase(const ControlModelContainerBase & rModel)236 ControlModelContainerBase::ControlModelContainerBase( const ControlModelContainerBase& rModel )
237     : ControlModelContainer_IBase( rModel )
238     , maContainerListeners( *this )
239     , maChangeListeners ( GetMutex() )
240     , mbGroupsUpToDate( sal_False )
241 {
242 }
243 
~ControlModelContainerBase()244 ControlModelContainerBase::~ControlModelContainerBase()
245 {
246     maModels.clear();
247     mbGroupsUpToDate = sal_False;
248 }
249 
ImplGetDefaultValue(sal_uInt16 nPropId) const250 Any ControlModelContainerBase::ImplGetDefaultValue( sal_uInt16 nPropId ) const
251 {
252     Any aAny;
253 
254     switch ( nPropId )
255     {
256         case BASEPROPERTY_DEFAULTCONTROL:
257             aAny <<= ::rtl::OUString::createFromAscii( szServiceName_UnoControlDialog );
258             break;
259         default:
260             aAny = UnoControlModel::ImplGetDefaultValue( nPropId );
261     }
262 
263     return aAny;
264 }
265 
getInfoHelper()266 ::cppu::IPropertyArrayHelper& ControlModelContainerBase::getInfoHelper()
267 {
268     static UnoPropertyArrayHelper* pHelper = NULL;
269     if ( !pHelper )
270     {
271         Sequence<sal_Int32> aIDs = ImplGetPropertyIds();
272         pHelper = new UnoPropertyArrayHelper( aIDs );
273     }
274     return *pHelper;
275 }
276 
dispose()277 void SAL_CALL ControlModelContainerBase::dispose(  )
278 {
279     // ====================================================================
280     // tell our listeners
281     {
282         ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
283 
284         EventObject aDisposeEvent;
285         aDisposeEvent.Source = static_cast< XAggregation* >( static_cast< ::cppu::OWeakAggObject* >( this ) );
286 
287         maContainerListeners.disposeAndClear( aDisposeEvent );
288         maChangeListeners.disposeAndClear( aDisposeEvent );
289     }
290 
291     // ====================================================================
292     // call the base class
293     UnoControlModel::dispose();
294 
295     // ====================================================================
296     // dispose our child models
297     // for this, collect the models (we collect them from maModels, and this is modified when disposing children)
298     ::std::vector< Reference< XControlModel > > aChildModels( maModels.size() );
299 
300     ::std::transform(
301         maModels.begin(), maModels.end(),               // source range
302         aChildModels.begin(),                           // target location
303         ::std::select1st< UnoControlModelHolder >( )    // operation to apply -> select the XControlModel part
304     );
305 
306     // now dispose
307     ::std::for_each( aChildModels.begin(), aChildModels.end(), DisposeControlModel() );
308     aChildModels.clear();
309 
310     mbGroupsUpToDate = sal_False;
311 }
312 
313 // XMultiPropertySet
getPropertySetInfo()314 Reference< XPropertySetInfo > ControlModelContainerBase::getPropertySetInfo(  )
315 {
316     static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
317     return xInfo;
318 }
Clone_Impl(ControlModelContainerBase & _rClone) const319 void ControlModelContainerBase::Clone_Impl(ControlModelContainerBase& _rClone) const
320 {
321     // clone all children
322     ::std::for_each(
323         maModels.begin(), maModels.end(),
324         CloneControlModel( _rClone.maModels )
325     );
326 }
Clone() const327 UnoControlModel* ControlModelContainerBase::Clone() const
328 {
329     // clone the container itself
330     ControlModelContainerBase* pClone = new ControlModelContainerBase( *this );
331     Clone_Impl(*pClone);
332 
333     return pClone;
334 }
335 
ImplFindElement(const::rtl::OUString & rName)336 ControlModelContainerBase::UnoControlModelHolderList::iterator ControlModelContainerBase::ImplFindElement( const ::rtl::OUString& rName )
337 {
338     return ::std::find_if( maModels.begin(), maModels.end(), FindControlModel( rName ) );
339 }
340 
341 // ::XMultiServiceFactory
createInstance(const::rtl::OUString & aServiceSpecifier)342 Reference< XInterface > ControlModelContainerBase::createInstance( const ::rtl::OUString& aServiceSpecifier )
343 {
344     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
345 
346     OGeometryControlModel_Base* pNewModel = NULL;
347 
348     const Reference< XMultiServiceFactory > xFactory( maContext.getLegacyServiceFactory() );
349     if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlEditModel ) == 0 )
350         pNewModel = new OGeometryControlModel< UnoControlEditModel >( xFactory );
351     else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlFormattedFieldModel ) == 0 )
352         pNewModel = new OGeometryControlModel< UnoControlFormattedFieldModel >( xFactory );
353     else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlFileControlModel ) == 0 )
354         pNewModel = new OGeometryControlModel< UnoControlFileControlModel >( xFactory );
355     else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlButtonModel ) == 0 )
356         pNewModel = new OGeometryControlModel< UnoControlButtonModel >( xFactory );
357     else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlImageControlModel ) == 0 )
358         pNewModel = new OGeometryControlModel< UnoControlImageControlModel >( xFactory );
359     else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlRadioButtonModel ) == 0 )
360         pNewModel = new OGeometryControlModel< UnoControlRadioButtonModel >( xFactory );
361     else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlCheckBoxModel ) == 0 )
362         pNewModel = new OGeometryControlModel< UnoControlCheckBoxModel >( xFactory );
363     else if ( aServiceSpecifier.compareToAscii( szServiceName_UnoControlFixedHyperlinkModel ) == 0 )
364         pNewModel = new OGeometryControlModel< UnoControlFixedHyperlinkModel >( xFactory );
365     else if ( aServiceSpecifier.compareToAscii( szServiceName_UnoControlFixedTextModel ) == 0 )
366         pNewModel = new OGeometryControlModel< UnoControlFixedTextModel >( xFactory );
367     else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlGroupBoxModel ) == 0 )
368         pNewModel = new OGeometryControlModel< UnoControlGroupBoxModel >( xFactory );
369     else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlListBoxModel ) == 0 )
370         pNewModel = new OGeometryControlModel< UnoControlListBoxModel >( xFactory );
371     else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlComboBoxModel ) == 0 )
372         pNewModel = new OGeometryControlModel< UnoControlComboBoxModel >( xFactory );
373     else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlDateFieldModel ) == 0 )
374         pNewModel = new OGeometryControlModel< UnoControlDateFieldModel >( xFactory );
375     else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlTimeFieldModel ) == 0 )
376         pNewModel = new OGeometryControlModel< UnoControlTimeFieldModel >( xFactory );
377     else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlNumericFieldModel ) == 0 )
378         pNewModel = new OGeometryControlModel< UnoControlNumericFieldModel >( xFactory );
379     else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlCurrencyFieldModel ) == 0 )
380         pNewModel = new OGeometryControlModel< UnoControlCurrencyFieldModel >( xFactory );
381     else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlPatternFieldModel ) == 0 )
382         pNewModel = new OGeometryControlModel< UnoControlPatternFieldModel >( xFactory );
383     else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlProgressBarModel ) == 0 )
384         pNewModel = new OGeometryControlModel< UnoControlProgressBarModel >( xFactory );
385     else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlScrollBarModel ) == 0 )
386         pNewModel = new OGeometryControlModel< UnoControlScrollBarModel >( xFactory );
387     else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlFixedLineModel ) == 0 )
388         pNewModel = new OGeometryControlModel< UnoControlFixedLineModel >( xFactory );
389     else if ( aServiceSpecifier.compareToAscii( szServiceName2_UnoControlRoadmapModel ) == 0 )
390         pNewModel = new OGeometryControlModel< UnoControlRoadmapModel >( xFactory );
391     else if ( aServiceSpecifier.compareToAscii( szServiceName_TreeControlModel ) == 0 )
392         pNewModel = new OGeometryControlModel< UnoTreeModel >( xFactory );
393     else if ( aServiceSpecifier.compareToAscii( szServiceName_GridControlModel ) == 0 )
394         pNewModel = new OGeometryControlModel< UnoGridModel >( xFactory );
395     else if ( aServiceSpecifier.compareToAscii( szServiceName_UnoControlTabPageContainerModel ) == 0 )
396         pNewModel = new OGeometryControlModel< UnoControlTabPageContainerModel >( xFactory );
397     else if ( aServiceSpecifier.compareToAscii( szServiceName_UnoControlTabPageModel ) == 0 )
398         pNewModel = new OGeometryControlModel< UnoControlTabPageModel >( xFactory );
399 
400     if ( !pNewModel )
401     {
402         if ( xFactory.is() )
403         {
404             Reference< XInterface > xObject = xFactory->createInstance( aServiceSpecifier );
405             Reference< XServiceInfo > xSI( xObject, UNO_QUERY );
406             Reference< XCloneable > xCloneAccess( xSI, UNO_QUERY );
407             Reference< XAggregation > xAgg( xCloneAccess, UNO_QUERY );
408             if ( xAgg.is() )
409             {
410                 if ( xSI->supportsService( ::rtl::OUString::createFromAscii( "com.sun.star.awt.UnoControlModel" ) ) )
411                 {
412                     // release 3 of the 4 references we have to the object
413                     xAgg.clear();
414                     xSI.clear();
415                     xObject.clear();
416 
417                     pNewModel = new OCommonGeometryControlModel( xCloneAccess, aServiceSpecifier );
418                 }
419             }
420         }
421     }
422 
423     Reference< XInterface > xNewModel = (::cppu::OWeakObject*)pNewModel;
424     return xNewModel;
425 }
426 
createInstanceWithArguments(const::rtl::OUString & ServiceSpecifier,const Sequence<Any> & i_arguments)427 Reference< XInterface > ControlModelContainerBase::createInstanceWithArguments( const ::rtl::OUString& ServiceSpecifier, const Sequence< Any >& i_arguments )
428 {
429     const Reference< XInterface > xInstance( createInstance( ServiceSpecifier ) );
430     const Reference< XInitialization > xInstanceInit( xInstance, UNO_QUERY );
431     ENSURE_OR_RETURN( xInstanceInit.is(), "ControlModelContainerBase::createInstanceWithArguments: can't pass the arguments!", xInstance );
432     xInstanceInit->initialize( i_arguments );
433     return xInstance;
434 }
435 
getAvailableServiceNames()436 Sequence< ::rtl::OUString > ControlModelContainerBase::getAvailableServiceNames()
437 {
438     static Sequence< ::rtl::OUString >* pNamesSeq = NULL;
439     if ( !pNamesSeq )
440     {
441         pNamesSeq = new Sequence< ::rtl::OUString >( 24 );
442         ::rtl::OUString* pNames = pNamesSeq->getArray();
443         pNames[0] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlEditModel );
444         pNames[1] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlFormattedFieldModel );
445         pNames[2] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlFileControlModel );
446         pNames[3] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlButtonModel );
447         pNames[4] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlImageControlModel );
448         pNames[5] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlRadioButtonModel );
449         pNames[6] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlCheckBoxModel );
450         pNames[7] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlFixedTextModel );
451         pNames[8] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlGroupBoxModel );
452         pNames[9] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlListBoxModel );
453         pNames[10] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlComboBoxModel );
454         pNames[11] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlDateFieldModel );
455         pNames[12] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlTimeFieldModel );
456         pNames[13] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlNumericFieldModel );
457         pNames[14] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlCurrencyFieldModel );
458         pNames[15] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlPatternFieldModel );
459         pNames[16] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlProgressBarModel );
460         pNames[17] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlScrollBarModel );
461         pNames[18] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlFixedLineModel );
462         pNames[19] = ::rtl::OUString::createFromAscii( szServiceName2_UnoControlRoadmapModel );
463         pNames[20] = ::rtl::OUString::createFromAscii( szServiceName_TreeControlModel );
464         pNames[21] = ::rtl::OUString::createFromAscii( szServiceName_GridControlModel );
465         pNames[22] = ::rtl::OUString::createFromAscii( szServiceName_UnoControlTabPageContainerModel );
466         pNames[23] = ::rtl::OUString::createFromAscii( szServiceName_UnoControlTabPageModel );
467     }
468     return *pNamesSeq;
469 }
470 
471 // XContainer
addContainerListener(const Reference<XContainerListener> & l)472 void ControlModelContainerBase::addContainerListener( const Reference< XContainerListener >& l )
473 {
474     maContainerListeners.addInterface( l );
475 }
476 
removeContainerListener(const Reference<XContainerListener> & l)477 void ControlModelContainerBase::removeContainerListener( const Reference< XContainerListener >& l )
478 {
479     maContainerListeners.removeInterface( l );
480 }
481 
482 // XElementAcces
getElementType()483 Type ControlModelContainerBase::getElementType()
484 {
485     Type aType = getCppuType( ( Reference< XControlModel>* ) NULL );
486     return aType;
487 }
488 
hasElements()489 sal_Bool ControlModelContainerBase::hasElements()
490 {
491     return !maModels.empty();
492 }
493 
494 // XNameContainer, XNameReplace, XNameAccess
replaceByName(const::rtl::OUString & aName,const Any & aElement)495 void ControlModelContainerBase::replaceByName( const ::rtl::OUString& aName, const Any& aElement )
496 {
497     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
498 
499     Reference< XControlModel > xNewModel;
500     aElement >>= xNewModel;
501     if ( !xNewModel.is() )
502         lcl_throwIllegalArgumentException();
503 
504     UnoControlModelHolderList::iterator aElementPos = ImplFindElement( aName );
505     if ( maModels.end() == aElementPos )
506         lcl_throwNoSuchElementException();
507 
508     // stop listening at the old model
509     stopControlListening( aElementPos->first );
510     Reference< XControlModel > xReplaced( aElementPos->first );
511     // remember the new model, and start listening
512     aElementPos->first = xNewModel;
513     startControlListening( xNewModel );
514 
515     ContainerEvent aEvent;
516     aEvent.Source = *this;
517     aEvent.Element = aElement;
518     aEvent.ReplacedElement <<= xReplaced;
519     aEvent.Accessor <<= aName;
520 
521     // notify the container listener
522     maContainerListeners.elementReplaced( aEvent );
523 
524     // our "tab controller model" has potentially changed -> notify this
525     implNotifyTabModelChange( aName );
526 }
527 
getByName(const::rtl::OUString & aName)528 Any ControlModelContainerBase::getByName( const ::rtl::OUString& aName )
529 {
530     UnoControlModelHolderList::iterator aElementPos = ImplFindElement( aName );
531     if ( maModels.end() == aElementPos )
532         lcl_throwNoSuchElementException();
533 
534     return makeAny( aElementPos->first );
535 }
536 
getElementNames()537 Sequence< ::rtl::OUString > ControlModelContainerBase::getElementNames()
538 {
539     Sequence< ::rtl::OUString > aNames( maModels.size() );
540 
541     ::std::transform(
542         maModels.begin(), maModels.end(),               // source range
543         aNames.getArray(),                              // target range
544         ::std::select2nd< UnoControlModelHolder >()     // operator to apply: select the second element (the name)
545     );
546 
547     return aNames;
548 }
549 
hasByName(const::rtl::OUString & aName)550 sal_Bool ControlModelContainerBase::hasByName( const ::rtl::OUString& aName )
551 {
552     return maModels.end() != ImplFindElement( aName );
553 }
554 
insertByName(const::rtl::OUString & aName,const Any & aElement)555 void ControlModelContainerBase::insertByName( const ::rtl::OUString& aName, const Any& aElement )
556 {
557     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
558 
559     Reference< XControlModel > xM;
560     aElement >>= xM;
561 
562     if ( xM.is() )
563     {
564         Reference< beans::XPropertySet > xProps( xM, UNO_QUERY );
565             if ( xProps.is() )
566             {
567 
568                 Reference< beans::XPropertySetInfo > xPropInfo = xProps.get()->getPropertySetInfo();
569 
570                 ::rtl::OUString sImageSourceProperty = GetPropertyName( BASEPROPERTY_IMAGEURL );
571                 if ( xPropInfo.get()->hasPropertyByName(  sImageSourceProperty ) && ImplHasProperty(BASEPROPERTY_DIALOGSOURCEURL) )
572                 {
573                     Any aUrl = xProps.get()->getPropertyValue(  sImageSourceProperty );
574 
575                     ::rtl::OUString absoluteUrl =
576                         getPhysicalLocation( getPropertyValue( GetPropertyName( BASEPROPERTY_DIALOGSOURCEURL ) ), aUrl );
577 
578                     aUrl <<= absoluteUrl;
579 
580                     xProps.get()->setPropertyValue(  sImageSourceProperty , aUrl );
581                 }
582             }
583     }
584 
585 
586 
587     if ( !aName.getLength() || !xM.is() )
588         lcl_throwIllegalArgumentException();
589 
590     UnoControlModelHolderList::iterator aElementPos = ImplFindElement( aName );
591     if ( maModels.end() != aElementPos )
592         lcl_throwElementExistException();
593 
594     maModels.push_back( UnoControlModelHolder( xM, aName ) );
595     mbGroupsUpToDate = sal_False;
596     startControlListening( xM );
597 
598     ContainerEvent aEvent;
599     aEvent.Source = *this;
600     aEvent.Element <<= aElement;
601     aEvent.Accessor <<= aName;
602     maContainerListeners.elementInserted( aEvent );
603 
604     // our "tab controller model" has potentially changed -> notify this
605     implNotifyTabModelChange( aName );
606 }
607 
removeByName(const::rtl::OUString & aName)608 void ControlModelContainerBase::removeByName( const ::rtl::OUString& aName )
609 {
610     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
611 
612     UnoControlModelHolderList::iterator aElementPos = ImplFindElement( aName );
613     if ( maModels.end() == aElementPos )
614         lcl_throwNoSuchElementException();
615 
616     ContainerEvent aEvent;
617     aEvent.Source = *this;
618     aEvent.Element <<= aElementPos->first;
619     aEvent.Accessor <<= aName;
620     maContainerListeners.elementRemoved( aEvent );
621 
622     stopControlListening( aElementPos->first );
623     Reference< XPropertySet > xPS( aElementPos->first, UNO_QUERY );
624     maModels.erase( aElementPos );
625     mbGroupsUpToDate = sal_False;
626 
627     if ( xPS.is() )
628         try
629         {
630             xPS->setPropertyValue( PROPERTY_RESOURCERESOLVER, makeAny( Reference< resource::XStringResourceResolver >() ) );
631         }
632         catch( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); }
633 
634     // our "tab controller model" has potentially changed -> notify this
635     implNotifyTabModelChange( aName );
636 }
637 
638 // ----------------------------------------------------------------------------
getGroupControl()639 sal_Bool SAL_CALL ControlModelContainerBase::getGroupControl(  )
640 {
641     return sal_True;
642 }
643 
644 // ----------------------------------------------------------------------------
setGroupControl(sal_Bool)645 void SAL_CALL ControlModelContainerBase::setGroupControl( sal_Bool )
646 {
647     DBG_ERROR( "UnoControlDialogModel::setGroupControl: explicit grouping not supported" );
648 }
649 
650 // ----------------------------------------------------------------------------
setControlModels(const Sequence<Reference<XControlModel>> & _rControls)651 void SAL_CALL ControlModelContainerBase::setControlModels( const Sequence< Reference< XControlModel > >& _rControls )
652 {
653     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
654 
655     // set the tab indexes according to the order of models in the sequence
656     const Reference< XControlModel >* pControls = _rControls.getConstArray( );
657     const Reference< XControlModel >* pControlsEnd = _rControls.getConstArray( ) + _rControls.getLength();
658 
659     sal_Int16 nTabIndex = 1;
660 
661     for ( ; pControls != pControlsEnd; ++pControls )
662     {
663         // look up the control in our own structure. This is to prevent invalid arguments
664         UnoControlModelHolderList::const_iterator aPos =
665             ::std::find_if(
666                 maModels.begin(), maModels.end(),
667                 CompareControlModel( *pControls )
668             );
669         if ( maModels.end() != aPos )
670         {
671             // okay, this is an existent model
672             // now set the TabIndex property (if applicable)
673             Reference< XPropertySet > xProps( aPos->first, UNO_QUERY );
674             Reference< XPropertySetInfo > xPSI;
675             if ( xProps.is() )
676                 xPSI = xProps->getPropertySetInfo();
677             if ( xPSI.is() && xPSI->hasPropertyByName( getTabIndexPropertyName() ) )
678                 xProps->setPropertyValue( getTabIndexPropertyName(), makeAny( nTabIndex++ ) );
679         }
680         mbGroupsUpToDate = sal_False;
681     }
682 }
683 
684 
685 typedef ::std::multimap< sal_Int32, Reference< XControlModel >, ::std::less< sal_Int32 > > MapIndexToModel;
686 
687 // ----------------------------------------------------------------------------
getControlModels()688 Sequence< Reference< XControlModel > > SAL_CALL ControlModelContainerBase::getControlModels(  )
689 {
690     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
691 
692     MapIndexToModel aSortedModels;
693         // will be the sorted container of all models which have a tab index property
694     ::std::vector< Reference< XControlModel > > aUnindexedModels;
695         // will be the container of all models which do not have a tab index property
696 
697     UnoControlModelHolderList::const_iterator aLoop = maModels.begin();
698     for ( ; aLoop != maModels.end(); ++aLoop )
699     {
700         Reference< XControlModel > xModel( aLoop->first );
701 
702         // see if the model has a TabIndex property
703         Reference< XPropertySet > xControlProps( xModel, UNO_QUERY );
704         Reference< XPropertySetInfo > xPSI;
705         if ( xControlProps.is() )
706             xPSI = xControlProps->getPropertySetInfo( );
707         DBG_ASSERT( xPSI.is(), "UnoControlDialogModel::getControlModels: invalid child model!" );
708 
709         // has it?
710         if ( xPSI.is() && xPSI->hasPropertyByName( getTabIndexPropertyName() ) )
711         {   // yes
712             sal_Int32 nTabIndex = -1;
713             xControlProps->getPropertyValue( getTabIndexPropertyName() ) >>= nTabIndex;
714 
715             aSortedModels.insert( MapIndexToModel::value_type( nTabIndex, xModel ) );
716         }
717         else if ( xModel.is() )
718             // no, it hasn't, but we have to include it, anyway
719             aUnindexedModels.push_back( xModel );
720     }
721 
722     // okay, here we have a container of all our models, sorted by tab index,
723     // plus a container of "unindexed" models
724     // -> merge them
725     Sequence< Reference< XControlModel > > aReturn( aUnindexedModels.size() + aSortedModels.size() );
726     ::std::transform(
727             aSortedModels.begin(), aSortedModels.end(),
728             ::std::copy( aUnindexedModels.begin(), aUnindexedModels.end(), aReturn.getArray() ),
729             ::std::select2nd< MapIndexToModel::value_type >( )
730         );
731 
732     return aReturn;
733 }
734 
735 // ----------------------------------------------------------------------------
setGroup(const Sequence<Reference<XControlModel>> &,const::rtl::OUString &)736 void SAL_CALL ControlModelContainerBase::setGroup( const Sequence< Reference< XControlModel > >&, const ::rtl::OUString& )
737 {
738     // not supported. We have only implicit grouping:
739     // We only have a sequence of control models, and we _know_ (yes, that's a HACK relying on
740     // implementation details) that VCL does grouping according to the order of controls automatically
741     // At least VCL does this for all we're interested in: Radio buttons.
742     DBG_ERROR( "UnoControlDialogModel::setGroup: grouping not supported" );
743 }
744 
745 ////----- XInitialization -------------------------------------------------------------------
initialize(const Sequence<Any> & rArguments)746 void SAL_CALL ControlModelContainerBase::initialize (const Sequence<Any>& rArguments)
747 {
748     sal_Int16 nPageId = -1;
749     if ( rArguments.getLength() == 1 )
750     {
751          if ( !( rArguments[ 0 ] >>= nPageId ))
752              throw lang::IllegalArgumentException();
753         m_nTabPageId = nPageId;
754     }
755     else
756         m_nTabPageId = -1;
757 }
getTabPageID()758 ::sal_Int16 SAL_CALL ControlModelContainerBase::getTabPageID()
759 {
760     return m_nTabPageId;
761 }
getEnabled()762 ::sal_Bool SAL_CALL ControlModelContainerBase::getEnabled()
763 {
764     return m_bEnabled;
765 }
setEnabled(::sal_Bool _enabled)766 void SAL_CALL ControlModelContainerBase::setEnabled( ::sal_Bool _enabled )
767 {
768     m_bEnabled = _enabled;
769 }
getTitle()770 ::rtl::OUString SAL_CALL ControlModelContainerBase::getTitle()
771 {
772     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
773     Reference<XPropertySet> xThis(*this,UNO_QUERY);
774     ::rtl::OUString sTitle;
775     xThis->getPropertyValue(GetPropertyName(BASEPROPERTY_TITLE)) >>= sTitle;
776     return sTitle;
777 }
setTitle(const::rtl::OUString & _title)778 void SAL_CALL ControlModelContainerBase::setTitle( const ::rtl::OUString& _title )
779 {
780     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
781     Reference<XPropertySet> xThis(*this,UNO_QUERY);
782     xThis->setPropertyValue(GetPropertyName(BASEPROPERTY_TITLE),makeAny(_title));
783 }
getImageURL()784 ::rtl::OUString SAL_CALL ControlModelContainerBase::getImageURL()
785 {
786     return m_sImageURL;
787 }
setImageURL(const::rtl::OUString & _imageurl)788 void SAL_CALL ControlModelContainerBase::setImageURL( const ::rtl::OUString& _imageurl )
789 {
790     m_sImageURL = _imageurl;
791 }
getToolTip()792 ::rtl::OUString SAL_CALL ControlModelContainerBase::getToolTip()
793 {
794     return m_sTooltip;
795 }
setToolTip(const::rtl::OUString & _tooltip)796 void SAL_CALL ControlModelContainerBase::setToolTip( const ::rtl::OUString& _tooltip )
797 {
798     m_sTooltip = _tooltip;
799 }
800 
801 // ----------------------------------------------------------------------------
802 namespace
803 {
804     enum GroupingMachineState
805     {
806         eLookingForGroup,
807         eExpandingGroup
808     };
809 
810     // ........................................................................
lcl_getDialogStep(const Reference<XControlModel> & _rxModel)811     static sal_Int32 lcl_getDialogStep( const Reference< XControlModel >& _rxModel )
812     {
813         sal_Int32 nStep = 0;
814         try
815         {
816             Reference< XPropertySet > xModelProps( _rxModel, UNO_QUERY );
817             xModelProps->getPropertyValue( getStepPropertyName() ) >>= nStep;
818         }
819         catch( const Exception& )
820         {
821             DBG_ERROR( "lcl_getDialogStep: caught an exception while determining the dialog page!" );
822         }
823         return nStep;
824     }
825 }
826 
827 // ----------------------------------------------------------------------------
getGroupCount()828 sal_Int32 SAL_CALL ControlModelContainerBase::getGroupCount(  )
829 {
830     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
831 
832     implUpdateGroupStructure();
833 
834     return maGroups.size();
835 }
836 
837 // ----------------------------------------------------------------------------
getGroup(sal_Int32 _nGroup,Sequence<Reference<XControlModel>> & _rGroup,::rtl::OUString & _rName)838 void SAL_CALL ControlModelContainerBase::getGroup( sal_Int32 _nGroup, Sequence< Reference< XControlModel > >& _rGroup, ::rtl::OUString& _rName )
839 {
840     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
841 
842     implUpdateGroupStructure();
843 
844     if ( ( _nGroup < 0 ) || ( _nGroup >= (sal_Int32)maGroups.size() ) )
845     {
846         DBG_ERROR( "UnoControlDialogModel::getGroup: invalid argument and I am not allowed to throw an exception!" );
847         _rGroup.realloc( 0 );
848         _rName = ::rtl::OUString();
849     }
850     else
851     {
852         AllGroups::const_iterator aGroupPos = maGroups.begin() + _nGroup;
853         _rGroup.realloc( aGroupPos->size() );
854         // copy the models
855         ::std::copy( aGroupPos->begin(), aGroupPos->end(), _rGroup.getArray() );
856         // give the group a name
857         _rName = ::rtl::OUString::valueOf( _nGroup );
858     }
859 }
860 
861 // ----------------------------------------------------------------------------
getGroupByName(const::rtl::OUString & _rName,Sequence<Reference<XControlModel>> & _rGroup)862 void SAL_CALL ControlModelContainerBase::getGroupByName( const ::rtl::OUString& _rName, Sequence< Reference< XControlModel > >& _rGroup )
863 {
864     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
865 
866     ::rtl::OUString sDummyName;
867     getGroup( _rName.toInt32( ), _rGroup, sDummyName );
868 }
869 
870 // ----------------------------------------------------------------------------
addChangesListener(const Reference<XChangesListener> & _rxListener)871 void SAL_CALL ControlModelContainerBase::addChangesListener( const Reference< XChangesListener >& _rxListener )
872 {
873     maChangeListeners.addInterface( _rxListener );
874 }
875 
876 // ----------------------------------------------------------------------------
removeChangesListener(const Reference<XChangesListener> & _rxListener)877 void SAL_CALL ControlModelContainerBase::removeChangesListener( const Reference< XChangesListener >& _rxListener )
878 {
879     maChangeListeners.removeInterface( _rxListener );
880 }
881 
882 // ----------------------------------------------------------------------------
implNotifyTabModelChange(const::rtl::OUString & _rAccessor)883 void ControlModelContainerBase::implNotifyTabModelChange( const ::rtl::OUString& _rAccessor )
884 {
885     // multiplex to our change listeners:
886     // the changes event
887     ChangesEvent aEvent;
888     aEvent.Source = *this;
889     aEvent.Base <<= aEvent.Source;  // the "base of the changes root" is also ourself
890     aEvent.Changes.realloc( 1 );    // exactly one change
891     aEvent.Changes[ 0 ].Accessor <<= _rAccessor;
892 
893 
894     Sequence< Reference< XInterface > > aChangeListeners( maChangeListeners.getElements() );
895     const Reference< XInterface >* pListener = aChangeListeners.getConstArray();
896     const Reference< XInterface >* pListenerEnd = aChangeListeners.getConstArray() + aChangeListeners.getLength();
897     for ( ; pListener != pListenerEnd; ++pListener )
898     {
899         if ( pListener->is() )
900             static_cast< XChangesListener* >( pListener->get() )->changesOccurred( aEvent );
901     }
902 }
903 
904 
905 // ----------------------------------------------------------------------------
implUpdateGroupStructure()906 void ControlModelContainerBase::implUpdateGroupStructure()
907 {
908     if ( mbGroupsUpToDate )
909         // nothing to do
910         return;
911 
912     // conditions for a group:
913     // * all elements of the group are radio buttons
914     // * all elements of the group are on the same dialog page
915     // * in the overall control order (determined by the tab index), all elements are subsequent
916 
917     maGroups.clear();
918 
919     Sequence< Reference< XControlModel > > aControlModels = getControlModels();
920     const Reference< XControlModel >* pControlModels = aControlModels.getConstArray();
921     const Reference< XControlModel >* pControlModelsEnd = pControlModels + aControlModels.getLength();
922 
923     // in extreme we have as much groups as controls
924     maGroups.reserve( aControlModels.getLength() );
925 
926     GroupingMachineState eState = eLookingForGroup;     // the current state of our machine
927     Reference< XServiceInfo > xModelSI;                 // for checking for a radion button
928     AllGroups::iterator aCurrentGroup = maGroups.end(); // the group which we're currently building
929     sal_Int32   nCurrentGroupStep = -1;                 // the step which all controls of the current group belong to
930     sal_Bool    bIsRadioButton;                         // is it a radio button?
931 
932 #if OSL_DEBUG_LEVEL > 1
933     ::std::vector< ::rtl::OUString > aCurrentGroupLabels;
934 #endif
935 
936     for ( ; pControlModels != pControlModelsEnd; ++pControlModels )
937     {
938         // we'll need this in every state
939         xModelSI = xModelSI.query( *pControlModels );
940         bIsRadioButton = xModelSI.is() && xModelSI->supportsService( ::rtl::OUString::createFromAscii( szServiceName2_UnoControlRadioButtonModel ) );
941 
942         switch ( eState )
943         {
944             case eLookingForGroup:
945             {
946                 if ( !bIsRadioButton )
947                     // this is no radio button -> still looking for the beginning of a group
948                     continue;
949                 // the current model is a radio button
950                 // -> we found the beginning of a new group
951                 // create the place for this group
952                 size_t nGroups = maGroups.size();
953                 maGroups.resize( nGroups + 1 );
954                 aCurrentGroup = maGroups.begin() + nGroups;
955                 // and add the (only, til now) member
956                 aCurrentGroup->push_back( *pControlModels );
957 
958                 // get the step which all controls of this group now have to belong to
959                 nCurrentGroupStep = lcl_getDialogStep( *pControlModels );
960                 // new state: looking for further members
961                 eState = eExpandingGroup;
962 
963 #if OSL_DEBUG_LEVEL > 1
964                 Reference< XPropertySet > xModelProps( *pControlModels, UNO_QUERY );
965                 ::rtl::OUString sLabel;
966                 if ( xModelProps.is() && xModelProps->getPropertySetInfo().is() && xModelProps->getPropertySetInfo()->hasPropertyByName( ::rtl::OUString::createFromAscii( "Label" ) ) )
967                     xModelProps->getPropertyValue( ::rtl::OUString::createFromAscii( "Label" ) ) >>= sLabel;
968                 aCurrentGroupLabels.push_back( sLabel );
969 #endif
970             }
971             break;
972 
973             case eExpandingGroup:
974             {
975                 if ( !bIsRadioButton )
976                 {   // no radio button -> the group is done
977                     aCurrentGroup = maGroups.end();
978                     eState = eLookingForGroup;
979 #if OSL_DEBUG_LEVEL > 1
980                     aCurrentGroupLabels.clear();
981 #endif
982                     continue;
983                 }
984 
985                 // it is a radio button - is it on the proper page?
986                 const sal_Int32 nThisModelStep = lcl_getDialogStep( *pControlModels );
987                 if  (   ( nThisModelStep == nCurrentGroupStep ) // the current button is on the same dialog page
988                     ||  ( 0 == nThisModelStep )                 // the current button appears on all pages
989                     )
990                 {
991                     // -> it belongs to the same group
992                     aCurrentGroup->push_back( *pControlModels );
993                     // state still is eExpandingGroup - we're looking for further elements
994                     eState = eExpandingGroup;
995 
996 #if OSL_DEBUG_LEVEL > 1
997                     Reference< XPropertySet > xModelProps( *pControlModels, UNO_QUERY );
998                     ::rtl::OUString sLabel;
999                     if ( xModelProps.is() && xModelProps->getPropertySetInfo().is() && xModelProps->getPropertySetInfo()->hasPropertyByName( ::rtl::OUString::createFromAscii( "Label" ) ) )
1000                         xModelProps->getPropertyValue( ::rtl::OUString::createFromAscii( "Label" ) ) >>= sLabel;
1001                     aCurrentGroupLabels.push_back( sLabel );
1002 #endif
1003                     continue;
1004                 }
1005 
1006                 // it's a radio button, but on a different page
1007                 // -> we open a new group for it
1008 
1009                 // close the old group
1010                 aCurrentGroup = maGroups.end();
1011 #if OSL_DEBUG_LEVEL > 1
1012                 aCurrentGroupLabels.clear();
1013 #endif
1014 
1015                 // open a new group
1016                 size_t nGroups = maGroups.size();
1017                 maGroups.resize( nGroups + 1 );
1018                 aCurrentGroup = maGroups.begin() + nGroups;
1019                 // and add the (only, til now) member
1020                 aCurrentGroup->push_back( *pControlModels );
1021 
1022                 nCurrentGroupStep = nThisModelStep;
1023 
1024                 // state is the same: we still are looking for further elements of the current group
1025                 eState = eExpandingGroup;
1026 #if OSL_DEBUG_LEVEL > 1
1027                 Reference< XPropertySet > xModelProps( *pControlModels, UNO_QUERY );
1028                 ::rtl::OUString sLabel;
1029                 if ( xModelProps.is() && xModelProps->getPropertySetInfo().is() && xModelProps->getPropertySetInfo()->hasPropertyByName( ::rtl::OUString::createFromAscii( "Label" ) ) )
1030                     xModelProps->getPropertyValue( ::rtl::OUString::createFromAscii( "Label" ) ) >>= sLabel;
1031                 aCurrentGroupLabels.push_back( sLabel );
1032 #endif
1033             }
1034             break;
1035         }
1036     }
1037 
1038     mbGroupsUpToDate = sal_True;
1039 }
1040 
1041 // ----------------------------------------------------------------------------
propertyChange(const PropertyChangeEvent & _rEvent)1042 void SAL_CALL ControlModelContainerBase::propertyChange( const PropertyChangeEvent& _rEvent )
1043 {
1044     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
1045 
1046     DBG_ASSERT( 0 == _rEvent.PropertyName.compareToAscii( "TabIndex" ),
1047         "UnoControlDialogModel::propertyChange: not listening for this property!" );
1048 
1049     // the accessor for the changed element
1050     ::rtl::OUString sAccessor;
1051     UnoControlModelHolderList::const_iterator aPos =
1052         ::std::find_if(
1053             maModels.begin(), maModels.end(),
1054             CompareControlModel( Reference< XControlModel >( _rEvent.Source, UNO_QUERY ) )
1055         );
1056     OSL_ENSURE( maModels.end() != aPos, "UnoControlDialogModel::propertyChange: don't know this model!" );
1057     if ( maModels.end() != aPos )
1058         sAccessor = aPos->second;
1059 
1060     // our groups are not up-to-date
1061     mbGroupsUpToDate = sal_False;
1062 
1063     // notify
1064     implNotifyTabModelChange( sAccessor );
1065 }
1066 
1067 // ----------------------------------------------------------------------------
disposing(const EventObject &)1068 void SAL_CALL ControlModelContainerBase::disposing( const EventObject& /*rEvent*/ )
1069 {
1070 }
1071 
1072 // ----------------------------------------------------------------------------
startControlListening(const Reference<XControlModel> & _rxChildModel)1073 void ControlModelContainerBase::startControlListening( const Reference< XControlModel >& _rxChildModel )
1074 {
1075     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
1076 
1077     Reference< XPropertySet > xModelProps( _rxChildModel, UNO_QUERY );
1078     Reference< XPropertySetInfo > xPSI;
1079     if ( xModelProps.is() )
1080         xPSI = xModelProps->getPropertySetInfo();
1081 
1082     if ( xPSI.is() && xPSI->hasPropertyByName( getTabIndexPropertyName() ) )
1083         xModelProps->addPropertyChangeListener( getTabIndexPropertyName(), this );
1084 }
1085 
1086 // ----------------------------------------------------------------------------
stopControlListening(const Reference<XControlModel> & _rxChildModel)1087 void ControlModelContainerBase::stopControlListening( const Reference< XControlModel >& _rxChildModel )
1088 {
1089     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
1090 
1091     Reference< XPropertySet > xModelProps( _rxChildModel, UNO_QUERY );
1092     Reference< XPropertySetInfo > xPSI;
1093     if ( xModelProps.is() )
1094         xPSI = xModelProps->getPropertySetInfo();
1095 
1096     if ( xPSI.is() && xPSI->hasPropertyByName( getTabIndexPropertyName() ) )
1097         xModelProps->removePropertyChangeListener( getTabIndexPropertyName(), this );
1098 }
1099 
1100 // ============================================================================
1101 // = class ResourceListener
1102 // ============================================================================
1103 
ResourceListener(const Reference<util::XModifyListener> & rListener)1104 ResourceListener::ResourceListener(
1105     const Reference< util::XModifyListener >& rListener ) :
1106     OWeakObject(),
1107     m_xListener( rListener ),
1108     m_bListening( false )
1109 {
1110 }
1111 
~ResourceListener()1112 ResourceListener::~ResourceListener()
1113 {
1114 }
1115 
1116 // XInterface
queryInterface(const Type & rType)1117 Any SAL_CALL ResourceListener::queryInterface( const Type& rType )
1118 {
1119     Any a = ::cppu::queryInterface(
1120                 rType ,
1121                 static_cast< XModifyListener* >( this ),
1122                 static_cast< XEventListener* >( this ));
1123 
1124     if ( a.hasValue() )
1125         return a;
1126 
1127     return OWeakObject::queryInterface( rType );
1128 }
1129 
acquire()1130 void SAL_CALL ResourceListener::acquire() throw ()
1131 {
1132     OWeakObject::acquire();
1133 }
1134 
release()1135 void SAL_CALL ResourceListener::release() throw ()
1136 {
1137     OWeakObject::release();
1138 }
1139 
startListening(const Reference<resource::XStringResourceResolver> & rResource)1140 void ResourceListener::startListening(
1141     const Reference< resource::XStringResourceResolver  >& rResource )
1142 {
1143     Reference< util::XModifyBroadcaster > xModifyBroadcaster( rResource, UNO_QUERY );
1144 
1145     {
1146         // --- SAFE ---
1147         ::osl::ResettableGuard < ::osl::Mutex > aGuard( m_aMutex );
1148         bool bListening( m_bListening );
1149         bool bResourceSet( m_xResource.is() );
1150         aGuard.clear();
1151         // --- SAFE ---
1152 
1153         if ( bListening && bResourceSet )
1154             stopListening();
1155 
1156         // --- SAFE ---
1157         aGuard.reset();
1158         m_xResource = rResource;
1159         aGuard.clear();
1160         // --- SAFE ---
1161     }
1162 
1163     Reference< util::XModifyListener > xThis( static_cast<OWeakObject*>( this ), UNO_QUERY );
1164     if ( xModifyBroadcaster.is() )
1165     {
1166         try
1167         {
1168             xModifyBroadcaster->addModifyListener( xThis );
1169 
1170             // --- SAFE ---
1171             ::osl::ResettableGuard < ::osl::Mutex > aGuard( m_aMutex );
1172             m_bListening = true;
1173             // --- SAFE ---
1174         }
1175         catch ( RuntimeException& )
1176         {
1177             throw;
1178         }
1179         catch ( Exception& )
1180         {
1181         }
1182     }
1183 }
1184 
stopListening()1185 void ResourceListener::stopListening()
1186 {
1187     Reference< util::XModifyBroadcaster > xModifyBroadcaster;
1188 
1189     // --- SAFE ---
1190     ::osl::ResettableGuard < ::osl::Mutex > aGuard( m_aMutex );
1191     if ( m_bListening && m_xResource.is() )
1192         xModifyBroadcaster = Reference< util::XModifyBroadcaster >( m_xResource, UNO_QUERY );
1193     aGuard.clear();
1194     // --- SAFE ---
1195 
1196     Reference< util::XModifyListener > xThis( static_cast< OWeakObject* >( this ), UNO_QUERY );
1197     if ( xModifyBroadcaster.is() )
1198     {
1199         try
1200         {
1201             // --- SAFE ---
1202             aGuard.reset();
1203             m_bListening = false;
1204             m_xResource.clear();
1205             aGuard.clear();
1206             // --- SAFE ---
1207 
1208             xModifyBroadcaster->removeModifyListener( xThis );
1209         }
1210         catch ( RuntimeException& )
1211         {
1212             throw;
1213         }
1214         catch ( Exception& )
1215         {
1216         }
1217     }
1218 }
1219 
1220 // XModifyListener
modified(const lang::EventObject & aEvent)1221 void SAL_CALL ResourceListener::modified(
1222     const lang::EventObject& aEvent )
1223 {
1224     Reference< util::XModifyListener > xListener;
1225 
1226     // --- SAFE ---
1227     ::osl::ResettableGuard < ::osl::Mutex > aGuard( m_aMutex );
1228     xListener = m_xListener;
1229     aGuard.clear();
1230     // --- SAFE ---
1231 
1232     if ( xListener.is() )
1233     {
1234         try
1235         {
1236             xListener->modified( aEvent );
1237         }
1238         catch ( RuntimeException& )
1239         {
1240             throw;
1241         }
1242         catch ( Exception& )
1243         {
1244         }
1245     }
1246 }
1247 
1248 // XEventListener
disposing(const EventObject & Source)1249 void SAL_CALL ResourceListener::disposing(
1250     const EventObject& Source )
1251 {
1252     Reference< lang::XEventListener > xListener;
1253     Reference< resource::XStringResourceResolver > xResource;
1254 
1255     // --- SAFE ---
1256     ::osl::ResettableGuard < ::osl::Mutex > aGuard( m_aMutex );
1257     Reference< XInterface > xIfacRes( m_xResource, UNO_QUERY );
1258     Reference< XInterface > xIfacList( m_xListener, UNO_QUERY );
1259     aGuard.clear();
1260     // --- SAFE ---
1261 
1262     if ( Source.Source == xIfacRes )
1263     {
1264         // --- SAFE ---
1265         aGuard.reset();
1266         m_bListening = false;
1267         xResource = m_xResource;
1268         xListener = Reference< lang::XEventListener >( m_xListener, UNO_QUERY );
1269         m_xResource.clear();
1270         aGuard.clear();
1271         // --- SAFE ---
1272 
1273         if ( xListener.is() )
1274         {
1275             try
1276             {
1277                 xListener->disposing( Source );
1278             }
1279             catch ( RuntimeException& )
1280             {
1281                 throw;
1282             }
1283             catch ( Exception& )
1284             {
1285             }
1286         }
1287     }
1288     else if ( Source.Source == xIfacList )
1289     {
1290         // --- SAFE ---
1291         aGuard.reset();
1292         m_bListening = false;
1293         xListener = Reference< lang::XEventListener >( m_xListener, UNO_QUERY );
1294         xResource = m_xResource;
1295         m_xResource.clear();
1296         m_xListener.clear();
1297         aGuard.clear();
1298         // --- SAFE ---
1299 
1300         // Remove ourself as listener from resource resolver
1301         Reference< util::XModifyBroadcaster > xModifyBroadcaster( xResource, UNO_QUERY );
1302         Reference< util::XModifyListener > xThis( static_cast< OWeakObject* >( this ), UNO_QUERY );
1303         if ( xModifyBroadcaster.is() )
1304         {
1305             try
1306             {
1307                 xModifyBroadcaster->removeModifyListener( xThis );
1308             }
1309             catch ( RuntimeException& )
1310             {
1311                 throw;
1312             }
1313             catch ( Exception& )
1314             {
1315             }
1316         }
1317     }
1318 }
1319 
1320 //===============================================================
1321 //  ----------------------------------------------------
1322 //  class DialogContainerControl
1323 //  ----------------------------------------------------
ControlContainerBase(const Reference<XMultiServiceFactory> & i_factory)1324 ControlContainerBase::ControlContainerBase( const Reference< XMultiServiceFactory >& i_factory )
1325     :ContainerControl_IBase( i_factory )
1326     ,mbSizeModified(false)
1327     ,mbPosModified(false)
1328 {
1329     maComponentInfos.nWidth = 280;
1330     maComponentInfos.nHeight = 400;
1331     mxListener = new ResourceListener( Reference< util::XModifyListener >(
1332                         static_cast< OWeakObject* >( this ), UNO_QUERY ));
1333 }
1334 
~ControlContainerBase()1335 ControlContainerBase::~ControlContainerBase()
1336 {
1337 }
1338 
createPeer(const Reference<XToolkit> & rxToolkit,const Reference<XWindowPeer> & rParentPeer)1339 void ControlContainerBase::createPeer( const Reference< XToolkit > & rxToolkit, const Reference< XWindowPeer >  & rParentPeer )
1340 {
1341     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
1342     UnoControlContainer::createPeer( rxToolkit, rParentPeer );
1343 }
1344 
ImplInsertControl(Reference<XControlModel> & rxModel,const::rtl::OUString & rName)1345 void ControlContainerBase::ImplInsertControl( Reference< XControlModel >& rxModel, const ::rtl::OUString& rName )
1346 {
1347     Reference< XPropertySet > xP( rxModel, UNO_QUERY );
1348 
1349     ::rtl::OUString aDefCtrl;
1350     xP->getPropertyValue( GetPropertyName( BASEPROPERTY_DEFAULTCONTROL ) ) >>= aDefCtrl;
1351     Reference < XControl > xCtrl;
1352     maContext.createComponent( aDefCtrl, xCtrl );
1353 
1354     DBG_ASSERT( xCtrl.is(), "ControlContainerBase::ImplInsertControl: could not create the control!" );
1355     if ( xCtrl.is() )
1356     {
1357         xCtrl->setModel( rxModel );
1358         addControl( rName, xCtrl );
1359             // will implicitly call addingControl, where we can add the PropertiesChangeListener to the model
1360             // (which we formerly did herein)
1361             // 08.01.2001 - 96008 - fs@openoffice.org
1362 
1363         ImplSetPosSize( xCtrl );
1364     }
1365 }
1366 
ImplRemoveControl(Reference<XControlModel> & rxModel)1367 void ControlContainerBase::ImplRemoveControl( Reference< XControlModel >& rxModel )
1368 {
1369     Sequence< Reference< XControl > > aControls = getControls();
1370     Reference< XControl > xCtrl = StdTabController::FindControl( aControls, rxModel );
1371     if ( xCtrl.is() )
1372     {
1373         removeControl( xCtrl );
1374         try
1375         {
1376             Reference< XComponent > const xControlComp( xCtrl, UNO_QUERY_THROW );
1377             xControlComp->dispose();
1378         }
1379         catch( Exception const & )
1380         {
1381             DBG_UNHANDLED_EXCEPTION();
1382         }
1383     }
1384 }
1385 
ImplSetPosSize(Reference<XControl> & rxCtrl)1386 void ControlContainerBase::ImplSetPosSize( Reference< XControl >& rxCtrl )
1387 {
1388     Reference< XPropertySet > xP( rxCtrl->getModel(), UNO_QUERY );
1389 
1390     sal_Int32 nX = 0, nY = 0, nWidth = 0, nHeight = 0;
1391     xP->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PositionX" ) ) ) >>= nX;
1392     xP->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PositionY" ) ) ) >>= nY;
1393     xP->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Width" ) ) ) >>= nWidth;
1394     xP->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Height" ) ) ) >>= nHeight;
1395     MapMode aMode( MAP_APPFONT );
1396     OutputDevice*pOutDev = Application::GetDefaultDevice();
1397     if ( pOutDev )
1398     {
1399         ::Size aTmp( nX, nY );
1400         aTmp = pOutDev->LogicToPixel( aTmp, aMode );
1401         nX = aTmp.Width();
1402         nY = aTmp.Height();
1403         aTmp = ::Size( nWidth, nHeight );
1404         aTmp = pOutDev->LogicToPixel( aTmp, aMode );
1405         nWidth = aTmp.Width();
1406         nHeight = aTmp.Height();
1407     }
1408     else
1409     {
1410         Reference< XWindowPeer > xPeer = ImplGetCompatiblePeer( sal_True );
1411         Reference< XDevice > xD( xPeer, UNO_QUERY );
1412 
1413         SimpleFontMetric aFM;
1414         FontDescriptor aFD;
1415         Any aVal = ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_FONTDESCRIPTOR ) );
1416         aVal >>= aFD;
1417         if ( aFD.StyleName.getLength() )
1418         {
1419             Reference< XFont > xFont = xD->getFont( aFD );
1420             aFM = xFont->getFontMetric();
1421         }
1422         else
1423         {
1424             Reference< XGraphics > xG = xD->createGraphics();
1425             aFM = xG->getFontMetric();
1426         }
1427 
1428         sal_Int16 nH = aFM.Ascent + aFM.Descent;
1429         sal_Int16 nW = nH/2;    // calculate average width?!
1430 
1431         nX *= nW;
1432         nX /= 4;
1433         nWidth *= nW;
1434         nWidth /= 4;
1435         nY *= nH;
1436         nY /= 8;
1437         nHeight *= nH;
1438         nHeight /= 8;
1439     }
1440     Reference < XWindow > xW( rxCtrl, UNO_QUERY );
1441     xW->setPosSize( nX, nY, nWidth, nHeight, PosSize::POSSIZE );
1442 }
1443 
dispose()1444 void ControlContainerBase::dispose()
1445 {
1446     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
1447 
1448     EventObject aEvt;
1449     aEvt.Source = static_cast< ::cppu::OWeakObject* >( this );
1450     // Notify our listener helper about dispose
1451     // --- SAFE ---
1452     ::osl::ResettableGuard< ::osl::Mutex > aGuard( GetMutex() );
1453     Reference< XEventListener > xListener( mxListener, UNO_QUERY );
1454     mxListener.clear();
1455     aGuard.clear();
1456     // --- SAFE ---
1457 
1458     if ( xListener.is() )
1459         xListener->disposing( aEvt );
1460     UnoControlContainer::dispose();
1461 }
1462 
disposing(const EventObject & Source)1463 void SAL_CALL ControlContainerBase::disposing(
1464     const EventObject& Source )
1465 {
1466     UnoControlContainer::disposing( Source );
1467 }
1468 
setModel(const Reference<XControlModel> & rxModel)1469 sal_Bool ControlContainerBase::setModel( const Reference< XControlModel >& rxModel )
1470 {
1471     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
1472 
1473     // destroy the old tab controller, if existent
1474     if ( mxTabController.is() )
1475     {
1476         mxTabController->setModel( NULL );                  // just to be sure, should not be necessary
1477         removeTabController( mxTabController );
1478         ::comphelper::disposeComponent( mxTabController );  // just to be sure, should not be necessary
1479         mxTabController.clear();
1480     }
1481 
1482     if ( getModel().is() )
1483     {
1484         Sequence< Reference< XControl > > aControls = getControls();
1485         const Reference< XControl >* pCtrls = aControls.getConstArray();
1486         const Reference< XControl >* pCtrlsEnd = pCtrls + aControls.getLength();
1487 
1488         for ( ; pCtrls < pCtrlsEnd; ++pCtrls )
1489             removeControl( *pCtrls );
1490                 // will implicitly call removingControl, which will remove the PropertyChangeListener
1491                 // (which we formerly did herein)
1492                 // 08.01.2001 - 96008 - fs@openoffice.org
1493 
1494         Reference< XContainer > xC( getModel(), UNO_QUERY );
1495         if ( xC.is() )
1496             xC->removeContainerListener( this );
1497 
1498         Reference< XChangesNotifier > xChangeNotifier( getModel(), UNO_QUERY );
1499         if ( xChangeNotifier.is() )
1500             xChangeNotifier->removeChangesListener( this );
1501     }
1502 
1503     sal_Bool bRet = UnoControl::setModel( rxModel );
1504 
1505     if ( getModel().is() )
1506     {
1507         Reference< XNameAccess > xNA( getModel(), UNO_QUERY );
1508         if ( xNA.is() )
1509         {
1510             Sequence< ::rtl::OUString > aNames = xNA->getElementNames();
1511             const ::rtl::OUString* pNames = aNames.getConstArray();
1512             sal_uInt32 nCtrls = aNames.getLength();
1513 
1514             Reference< XControlModel > xCtrlModel;
1515             for( sal_uInt32 n = 0; n < nCtrls; ++n, ++pNames )
1516             {
1517                 xNA->getByName( *pNames ) >>= xCtrlModel;
1518                 ImplInsertControl( xCtrlModel, *pNames );
1519             }
1520         }
1521 
1522         Reference< XContainer > xC( getModel(), UNO_QUERY );
1523         if ( xC.is() )
1524             xC->addContainerListener( this );
1525 
1526         Reference< XChangesNotifier > xChangeNotifier( getModel(), UNO_QUERY );
1527         if ( xChangeNotifier.is() )
1528             xChangeNotifier->addChangesListener( this );
1529     }
1530 
1531     Reference< XTabControllerModel > xTabbing( getModel(), UNO_QUERY );
1532     if ( xTabbing.is() )
1533     {
1534         mxTabController = new StdTabController;
1535         mxTabController->setModel( xTabbing );
1536         addTabController( mxTabController );
1537     }
1538     ImplStartListingForResourceEvents();
1539 
1540     return bRet;
1541 }
setDesignMode(sal_Bool bOn)1542 void ControlContainerBase::setDesignMode( sal_Bool bOn )
1543 {
1544     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
1545     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
1546 
1547     UnoControl::setDesignMode( bOn );
1548 
1549     Sequence< Reference< XControl > > xCtrls = getControls();
1550     sal_Int32 nControls = xCtrls.getLength();
1551     Reference< XControl >* pControls = xCtrls.getArray();
1552     for ( sal_Int32 n = 0; n < nControls; n++ )
1553         pControls[n]->setDesignMode( bOn );
1554 
1555     // #109067# in design mode the tab controller is not notified about
1556     // tab index changes, therefore the tab order must be activated
1557     // when switching from design mode to live mode
1558     if ( mxTabController.is() && !bOn )
1559         mxTabController->activateTabOrder();
1560 }
1561 
elementInserted(const ContainerEvent & Event)1562 void ControlContainerBase::elementInserted( const ContainerEvent& Event )
1563 {
1564     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
1565 
1566     Reference< XControlModel > xModel;
1567     ::rtl::OUString aName;
1568 
1569     Event.Accessor >>= aName;
1570     Event.Element >>= xModel;
1571     ENSURE_OR_RETURN_VOID( xModel.is(), "ControlContainerBase::elementInserted: illegal element!" );
1572     try
1573     {
1574         ImplInsertControl( xModel, aName );
1575     }
1576     catch ( const RuntimeException& e ) { throw; }
1577     catch( const Exception& )
1578     {
1579         DBG_UNHANDLED_EXCEPTION();
1580     }
1581 }
1582 
elementRemoved(const ContainerEvent & Event)1583 void ControlContainerBase::elementRemoved( const ContainerEvent& Event )
1584 {
1585     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
1586 
1587     Reference< XControlModel > xModel;
1588     Event.Element >>= xModel;
1589     ENSURE_OR_RETURN_VOID( xModel.is(), "ControlContainerBase::elementRemoved: illegal element!" );
1590     try
1591     {
1592         ImplRemoveControl( xModel );
1593     }
1594     catch ( const RuntimeException& e ) { throw; }
1595     catch( const Exception& )
1596     {
1597         DBG_UNHANDLED_EXCEPTION();
1598     }
1599 }
1600 
elementReplaced(const ContainerEvent & Event)1601 void ControlContainerBase::elementReplaced( const ContainerEvent& Event )
1602 {
1603     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
1604 
1605     Reference< XControlModel > xModel;
1606     Event.ReplacedElement >>= xModel;
1607     try
1608     {
1609         OSL_ENSURE( xModel.is(), "ControlContainerBase::elementReplaced: invalid ReplacedElement!" );
1610         if ( xModel.is() )
1611             ImplRemoveControl( xModel );
1612     }
1613     catch ( const RuntimeException& e ) { throw; }
1614     catch( const Exception& )
1615     {
1616         DBG_UNHANDLED_EXCEPTION();
1617     }
1618 
1619     ::rtl::OUString aName;
1620     Event.Accessor >>= aName;
1621     Event.Element >>= xModel;
1622     ENSURE_OR_RETURN_VOID( xModel.is(), "ControlContainerBase::elementReplaced: invalid new element!" );
1623     try
1624     {
1625         ImplInsertControl( xModel, aName );
1626     }
1627     catch ( const RuntimeException& e ) { throw; }
1628     catch( const Exception& )
1629     {
1630         DBG_UNHANDLED_EXCEPTION();
1631     }
1632 }
1633 
1634 // XPropertiesChangeListener
ImplModelPropertiesChanged(const Sequence<PropertyChangeEvent> & rEvents)1635 void ControlContainerBase::ImplModelPropertiesChanged( const Sequence< PropertyChangeEvent >& rEvents )
1636 {
1637     if( !isDesignMode() && !mbCreatingCompatiblePeer )
1638     {
1639         ::rtl::OUString s1( RTL_CONSTASCII_USTRINGPARAM( "PositionX" ) );
1640         ::rtl::OUString s2( RTL_CONSTASCII_USTRINGPARAM( "PositionY" ) );
1641         ::rtl::OUString s3( RTL_CONSTASCII_USTRINGPARAM( "Width" ) );
1642         ::rtl::OUString s4( RTL_CONSTASCII_USTRINGPARAM( "Height" ) );
1643 
1644         sal_Int32 nLen = rEvents.getLength();
1645         for( sal_Int32 i = 0; i < nLen; i++ )
1646         {
1647             const PropertyChangeEvent& rEvt = rEvents.getConstArray()[i];
1648             Reference< XControlModel > xModel( rEvt.Source, UNO_QUERY );
1649             sal_Bool bOwnModel = (XControlModel*)xModel.get() == (XControlModel*)getModel().get();
1650             if ( ( rEvt.PropertyName == s1 ) ||
1651                  ( rEvt.PropertyName == s2 ) ||
1652                  ( rEvt.PropertyName == s3 ) ||
1653                  ( rEvt.PropertyName == s4 ) )
1654             {
1655                 if ( bOwnModel )
1656                 {
1657                     if ( !mbPosModified && !mbSizeModified )
1658                     {
1659                         // Don't set new pos/size if we get new values from window listener
1660                         Reference< XControl > xThis( (XAggregation*)(::cppu::OWeakAggObject*)this, UNO_QUERY );
1661                         ImplSetPosSize( xThis );
1662                     }
1663                 }
1664                 else
1665                 {
1666                     Sequence<Reference<XControl> > aControlSequence(getControls());
1667                     Reference<XControl> aControlRef( StdTabController::FindControl( aControlSequence, xModel ) );
1668                     ImplSetPosSize( aControlRef );
1669                 }
1670                 break;
1671             }
1672         }
1673     }
1674 
1675     UnoControlContainer::ImplModelPropertiesChanged( rEvents );
1676 }
1677 
addingControl(const Reference<XControl> & _rxControl)1678 void ControlContainerBase::addingControl( const Reference< XControl >& _rxControl )
1679 {
1680     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
1681     UnoControlContainer::addingControl( _rxControl );
1682 
1683     if ( _rxControl.is() )
1684     {
1685         Reference< XMultiPropertySet > xProps( _rxControl->getModel(), UNO_QUERY );
1686         if ( xProps.is() )
1687         {
1688             Sequence< ::rtl::OUString > aNames( 4 );
1689             ::rtl::OUString* pNames = aNames.getArray();
1690             *pNames++ = ::rtl::OUString::createFromAscii( "PositionX" );
1691             *pNames++ = ::rtl::OUString::createFromAscii( "PositionY" );
1692             *pNames++ = ::rtl::OUString::createFromAscii( "Width" );
1693             *pNames++ = ::rtl::OUString::createFromAscii( "Height" );
1694 
1695             xProps->addPropertiesChangeListener( aNames, this );
1696         }
1697     }
1698 }
1699 
removingControl(const Reference<XControl> & _rxControl)1700 void ControlContainerBase::removingControl( const Reference< XControl >& _rxControl )
1701 {
1702     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
1703     UnoControlContainer::removingControl( _rxControl );
1704 
1705     if ( _rxControl.is() )
1706     {
1707         Reference< XMultiPropertySet > xProps( _rxControl->getModel(), UNO_QUERY );
1708         if ( xProps.is() )
1709             xProps->removePropertiesChangeListener( this );
1710     }
1711 
1712 }
1713 
changesOccurred(const ChangesEvent &)1714 void SAL_CALL ControlContainerBase::changesOccurred( const ChangesEvent& )
1715 {
1716     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
1717     // a tab controller model may have changed
1718 
1719     // #109067# in design mode don't notify the tab controller
1720     // about tab index changes
1721     if ( mxTabController.is() && !mbDesignMode )
1722         mxTabController->activateTabOrder();
1723 }
lcl_ApplyResolverToNestedContainees(const Reference<resource::XStringResourceResolver> & xStringResourceResolver,const Reference<XControlContainer> & xContainer)1724 void lcl_ApplyResolverToNestedContainees(  const Reference< resource::XStringResourceResolver >& xStringResourceResolver, const Reference< XControlContainer >& xContainer )
1725 {
1726     rtl::OUString aPropName( PROPERTY_RESOURCERESOLVER );
1727 
1728     Any xNewStringResourceResolver; xNewStringResourceResolver <<= xStringResourceResolver;
1729 
1730     Sequence< rtl::OUString > aPropNames(1);
1731     aPropNames[0] = aPropName;
1732 
1733     const Sequence< Reference< awt::XControl > > aSeq = xContainer->getControls();
1734     for ( sal_Int32 i = 0; i < aSeq.getLength(); i++ )
1735     {
1736         Reference< XControl > xControl( aSeq[i] );
1737         Reference< XPropertySet > xPropertySet;
1738 
1739         if ( xControl.is() )
1740             xPropertySet = Reference< XPropertySet >( xControl->getModel(), UNO_QUERY );
1741 
1742         if ( !xPropertySet.is() )
1743             continue;
1744 
1745         try
1746         {
1747             Reference< resource::XStringResourceResolver > xCurrStringResourceResolver;
1748             Any aOldValue = xPropertySet->getPropertyValue( aPropName );
1749             if  (   ( aOldValue >>= xCurrStringResourceResolver )
1750                 &&  ( xStringResourceResolver == xCurrStringResourceResolver )
1751                 )
1752             {
1753                 Reference< XMultiPropertySet >  xMultiPropSet( xPropertySet, UNO_QUERY );
1754                 Reference< XPropertiesChangeListener > xListener( xPropertySet, UNO_QUERY );
1755                 xMultiPropSet->firePropertiesChangeEvent( aPropNames, xListener );
1756             }
1757             else
1758                 xPropertySet->setPropertyValue( aPropName, xNewStringResourceResolver );
1759         }
1760         /*catch ( NoSuchElementException& )*/ // that's nonsense, this is never thrown above ...
1761         catch ( const Exception& )
1762         {
1763         }
1764 
1765         uno::Reference< XControlContainer > xNestedContainer( xControl, uno::UNO_QUERY );
1766         if ( xNestedContainer.is() )
1767             lcl_ApplyResolverToNestedContainees(  xStringResourceResolver, xNestedContainer );
1768 
1769     }
1770 
1771 }
ImplStartListingForResourceEvents()1772 void ControlContainerBase::ImplStartListingForResourceEvents()
1773 {
1774     Reference< resource::XStringResourceResolver > xStringResourceResolver;
1775 
1776     ImplGetPropertyValue( PROPERTY_RESOURCERESOLVER ) >>= xStringResourceResolver;
1777 
1778     // Add our helper as listener to retrieve notifications about changes
1779     Reference< util::XModifyListener > rListener( mxListener );
1780     ResourceListener* pResourceListener = static_cast< ResourceListener* >( rListener.get() );
1781 
1782     // resource listener will stop listening if resolver reference is empty
1783     if ( pResourceListener )
1784         pResourceListener->startListening( xStringResourceResolver );
1785     ImplUpdateResourceResolver();
1786 }
1787 
ImplUpdateResourceResolver()1788 void ControlContainerBase::ImplUpdateResourceResolver()
1789 {
1790     rtl::OUString aPropName( PROPERTY_RESOURCERESOLVER );
1791     Reference< resource::XStringResourceResolver > xStringResourceResolver;
1792 
1793     ImplGetPropertyValue( aPropName ) >>= xStringResourceResolver;
1794     if ( !xStringResourceResolver.is() )
1795         return;
1796 
1797     lcl_ApplyResolverToNestedContainees(  xStringResourceResolver, this );
1798 
1799     // propagate resource resolver changes to language dependent props of the dialog
1800     Reference< XPropertySet > xPropertySet( getModel(), UNO_QUERY );
1801     if ( xPropertySet.is() )
1802     {
1803         Reference< XMultiPropertySet >  xMultiPropSet( xPropertySet, UNO_QUERY );
1804         Reference< XPropertiesChangeListener > xListener( xPropertySet, UNO_QUERY );
1805         xMultiPropSet->firePropertiesChangeEvent( lcl_getLanguageDependentProperties(), xListener );
1806     }
1807 }
1808 
1809 
Impl_getGraphicFromURL_nothrow(const::rtl::OUString & _rURL)1810 uno::Reference< graphic::XGraphic > ControlContainerBase::Impl_getGraphicFromURL_nothrow( const ::rtl::OUString& _rURL )
1811 {
1812     uno::Reference< graphic::XGraphic > xGraphic;
1813     if ( !_rURL.getLength() )
1814         return xGraphic;
1815 
1816     try
1817     {
1818         uno::Reference< graphic::XGraphicProvider > xProvider;
1819         if ( maContext.createComponent( "com.sun.star.graphic.GraphicProvider", xProvider ) )
1820         {
1821             uno::Sequence< beans::PropertyValue > aMediaProperties(1);
1822             aMediaProperties[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) );
1823             aMediaProperties[0].Value <<= _rURL;
1824             xGraphic = xProvider->queryGraphic( aMediaProperties );
1825         }
1826     }
1827     catch( const Exception& )
1828     {
1829         DBG_UNHANDLED_EXCEPTION();
1830     }
1831 
1832     return xGraphic;
1833 }
1834 ////    ----------------------------------------------------
1835 ////    Helper Method to convert relative url to physical location
1836 ////    ----------------------------------------------------
1837 
getPhysicalLocation(const::com::sun::star::uno::Any & rbase,const::com::sun::star::uno::Any & rUrl)1838 ::rtl::OUString getPhysicalLocation( const ::com::sun::star::uno::Any& rbase, const ::com::sun::star::uno::Any& rUrl )
1839 {
1840 
1841     ::rtl::OUString baseLocation;
1842     ::rtl::OUString url;
1843 
1844     rbase  >>= baseLocation;
1845     rUrl  >>= url;
1846 
1847     ::rtl::OUString absoluteURL( url );
1848     if ( url.getLength() > 0 )
1849     {
1850         INetURLObject urlObj(baseLocation);
1851         urlObj.removeSegment();
1852         baseLocation = urlObj.GetMainURL( INetURLObject::NO_DECODE );
1853 
1854         const INetURLObject protocolCheck( url );
1855         const INetProtocol protocol = protocolCheck.GetProtocol();
1856         if ( protocol == INET_PROT_NOT_VALID )
1857         {
1858             ::rtl::OUString testAbsoluteURL;
1859             if ( ::osl::FileBase::E_None == ::osl::FileBase::getAbsoluteFileURL( baseLocation, url, testAbsoluteURL ) )
1860                 absoluteURL = testAbsoluteURL;
1861         }
1862     }
1863 
1864     return absoluteURL;
1865 }
1866