xref: /trunk/main/fpicker/source/office/commonpicker.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
1*b557fc96SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b557fc96SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b557fc96SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b557fc96SAndrew Rist  * distributed with this work for additional information
6*b557fc96SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b557fc96SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b557fc96SAndrew Rist  * "License"); you may not use this file except in compliance
9*b557fc96SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*b557fc96SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*b557fc96SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b557fc96SAndrew Rist  * software distributed under the License is distributed on an
15*b557fc96SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b557fc96SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b557fc96SAndrew Rist  * specific language governing permissions and limitations
18*b557fc96SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*b557fc96SAndrew Rist  *************************************************************/
21*b557fc96SAndrew Rist 
22*b557fc96SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_fpicker.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "commonpicker.hxx"
28cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
29cdf0e10cSrcweir #include <com/sun/star/beans/NamedValue.hpp>
30cdf0e10cSrcweir #include <vcl/svapp.hxx>
31cdf0e10cSrcweir #include <vos/mutex.hxx>
32cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
33cdf0e10cSrcweir #include <comphelper/weakeventlistener.hxx>
34cdf0e10cSrcweir #include <comphelper/types.hxx>
35cdf0e10cSrcweir #include <vcl/msgbox.hxx>
36cdf0e10cSrcweir #include "iodlg.hxx"
37cdf0e10cSrcweir 
38cdf0e10cSrcweir //.........................................................................
39cdf0e10cSrcweir namespace svt
40cdf0e10cSrcweir {
41cdf0e10cSrcweir //.........................................................................
42cdf0e10cSrcweir 
43cdf0e10cSrcweir #define PROPERTY_ID_HELPURL     1
44cdf0e10cSrcweir #define PROPERTY_ID_WINDOW      2
45cdf0e10cSrcweir 
46cdf0e10cSrcweir     // using --------------------------------------------------------------
47cdf0e10cSrcweir 
48cdf0e10cSrcweir     using namespace     ::com::sun::star::lang;
49cdf0e10cSrcweir     using namespace     ::com::sun::star::ui::dialogs;
50cdf0e10cSrcweir     using namespace     ::com::sun::star::uno;
51cdf0e10cSrcweir     using namespace     ::com::sun::star::beans;
52cdf0e10cSrcweir     using namespace     ::comphelper;
53cdf0e10cSrcweir 
54cdf0e10cSrcweir     //---------------------------------------------------------------------
OCommonPicker(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & _rxFactory)55cdf0e10cSrcweir     OCommonPicker::OCommonPicker( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory )
56cdf0e10cSrcweir         :OCommonPicker_Base( m_aMutex )
57cdf0e10cSrcweir         ,OPropertyContainer( GetBroadcastHelper() )
58cdf0e10cSrcweir         ,m_xORB( _rxFactory )
59cdf0e10cSrcweir         ,m_pDlg( NULL )
60cdf0e10cSrcweir         ,m_nCancelEvent( 0 )
61cdf0e10cSrcweir         ,m_bExecuting( sal_False )
62cdf0e10cSrcweir     {
63cdf0e10cSrcweir         // the two properties we have
64cdf0e10cSrcweir         registerProperty(
65cdf0e10cSrcweir             ::rtl::OUString::createFromAscii( "HelpURL" ), PROPERTY_ID_HELPURL,
66cdf0e10cSrcweir             PropertyAttribute::TRANSIENT,
67cdf0e10cSrcweir             &m_sHelpURL, ::getCppuType( &m_sHelpURL )
68cdf0e10cSrcweir         );
69cdf0e10cSrcweir 
70cdf0e10cSrcweir         registerProperty(
71cdf0e10cSrcweir             ::rtl::OUString::createFromAscii( "Window" ), PROPERTY_ID_WINDOW,
72cdf0e10cSrcweir             PropertyAttribute::TRANSIENT | PropertyAttribute::READONLY,
73cdf0e10cSrcweir             &m_xWindow, ::getCppuType( &m_xWindow )
74cdf0e10cSrcweir         );
75cdf0e10cSrcweir     }
76cdf0e10cSrcweir 
77cdf0e10cSrcweir     //---------------------------------------------------------------------
~OCommonPicker()78cdf0e10cSrcweir     OCommonPicker::~OCommonPicker()
79cdf0e10cSrcweir     {
80cdf0e10cSrcweir         if ( !GetBroadcastHelper().bDisposed )
81cdf0e10cSrcweir         {
82cdf0e10cSrcweir             acquire();
83cdf0e10cSrcweir             dispose();
84cdf0e10cSrcweir         }
85cdf0e10cSrcweir     }
86cdf0e10cSrcweir 
87cdf0e10cSrcweir     //---------------------------------------------------------------------
88cdf0e10cSrcweir     // disambiguate XInterface
89cdf0e10cSrcweir     //---------------------------------------------------------------------
IMPLEMENT_FORWARD_XINTERFACE2(OCommonPicker,OCommonPicker_Base,OPropertyContainer)90cdf0e10cSrcweir     IMPLEMENT_FORWARD_XINTERFACE2( OCommonPicker, OCommonPicker_Base, OPropertyContainer )
91cdf0e10cSrcweir 
92cdf0e10cSrcweir     //---------------------------------------------------------------------
93cdf0e10cSrcweir     // disambiguate XTypeProvider
94cdf0e10cSrcweir     //---------------------------------------------------------------------
95cdf0e10cSrcweir     IMPLEMENT_FORWARD_XTYPEPROVIDER2( OCommonPicker, OCommonPicker_Base, OPropertyContainer )
96cdf0e10cSrcweir 
97cdf0e10cSrcweir     //---------------------------------------------------------------------
98cdf0e10cSrcweir     // XComponent related methods
99cdf0e10cSrcweir     //---------------------------------------------------------------------
100cdf0e10cSrcweir     void OCommonPicker::checkAlive() const SAL_THROW( (DisposedException) )
101cdf0e10cSrcweir     {
102cdf0e10cSrcweir         if ( GetBroadcastHelper().bInDispose || GetBroadcastHelper().bDisposed )
103cdf0e10cSrcweir             throw DisposedException();
104cdf0e10cSrcweir     }
105cdf0e10cSrcweir 
prepareDialog()106cdf0e10cSrcweir     void OCommonPicker::prepareDialog()
107cdf0e10cSrcweir     {
108cdf0e10cSrcweir         if ( !getDialog() )
109cdf0e10cSrcweir             createPicker();
110cdf0e10cSrcweir 
111cdf0e10cSrcweir         // set the title
112cdf0e10cSrcweir         if ( m_aTitle.getLength() > 0 )
113cdf0e10cSrcweir             getDialog()->SetText( m_aTitle );
114cdf0e10cSrcweir     }
115cdf0e10cSrcweir 
116cdf0e10cSrcweir     //---------------------------------------------------------------------
disposing()117cdf0e10cSrcweir     void SAL_CALL OCommonPicker::disposing()
118cdf0e10cSrcweir     {
119cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
120cdf0e10cSrcweir 
121cdf0e10cSrcweir         stopWindowListening();
122cdf0e10cSrcweir 
123cdf0e10cSrcweir         if ( m_nCancelEvent )
124cdf0e10cSrcweir             Application::RemoveUserEvent( m_nCancelEvent );
125cdf0e10cSrcweir 
126cdf0e10cSrcweir         {
127cdf0e10cSrcweir             ::osl::MutexGuard aOwnGuard( m_aMutex );
128cdf0e10cSrcweir             if ( m_bExecuting && m_pDlg )
129cdf0e10cSrcweir                 m_pDlg->EndDialog( RET_CANCEL );
130cdf0e10cSrcweir         }
131cdf0e10cSrcweir 
132cdf0e10cSrcweir         delete m_pDlg;
133cdf0e10cSrcweir         m_pDlg = NULL;
134cdf0e10cSrcweir         m_xWindow = NULL;
135cdf0e10cSrcweir         m_xDialogParent = NULL;
136cdf0e10cSrcweir     }
137cdf0e10cSrcweir 
138cdf0e10cSrcweir     //---------------------------------------------------------------------
stopWindowListening()139cdf0e10cSrcweir     void OCommonPicker::stopWindowListening()
140cdf0e10cSrcweir     {
141cdf0e10cSrcweir         disposeComponent( m_xWindowListenerAdapter );
142cdf0e10cSrcweir         disposeComponent( m_xParentListenerAdapter );
143cdf0e10cSrcweir     }
144cdf0e10cSrcweir 
145cdf0e10cSrcweir     //---------------------------------------------------------------------
146cdf0e10cSrcweir     // XEventListener
147cdf0e10cSrcweir     //---------------------------------------------------------------------
disposing(const EventObject & _rSource)148cdf0e10cSrcweir     void SAL_CALL OCommonPicker::disposing( const EventObject& _rSource ) throw (RuntimeException)
149cdf0e10cSrcweir     {
150cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
151cdf0e10cSrcweir         sal_Bool bDialogDying = _rSource.Source == m_xWindow;
152cdf0e10cSrcweir         sal_Bool bParentDying = _rSource.Source == m_xDialogParent;
153cdf0e10cSrcweir 
154cdf0e10cSrcweir         if ( bDialogDying || bParentDying )
155cdf0e10cSrcweir         {
156cdf0e10cSrcweir             stopWindowListening();
157cdf0e10cSrcweir 
158cdf0e10cSrcweir             if ( !bDialogDying )    // it's the parent which is dying -> delete the dialog
159cdf0e10cSrcweir                 delete m_pDlg;
160cdf0e10cSrcweir 
161cdf0e10cSrcweir             m_pDlg = NULL;
162cdf0e10cSrcweir             m_xWindow = NULL;
163cdf0e10cSrcweir             m_xDialogParent = NULL;
164cdf0e10cSrcweir         }
165cdf0e10cSrcweir         else
166cdf0e10cSrcweir         {
167cdf0e10cSrcweir             DBG_ERROR( "OCommonPicker::disposing: where did this come from?" );
168cdf0e10cSrcweir         }
169cdf0e10cSrcweir     }
170cdf0e10cSrcweir 
171cdf0e10cSrcweir     //---------------------------------------------------------------------
172cdf0e10cSrcweir     // property set related methods
173cdf0e10cSrcweir     //---------------------------------------------------------------------
createArrayHelper() const174cdf0e10cSrcweir     ::cppu::IPropertyArrayHelper* OCommonPicker::createArrayHelper( ) const
175cdf0e10cSrcweir     {
176cdf0e10cSrcweir         Sequence< Property > aProps;
177cdf0e10cSrcweir         describeProperties( aProps );
178cdf0e10cSrcweir         return new cppu::OPropertyArrayHelper( aProps );
179cdf0e10cSrcweir     }
180cdf0e10cSrcweir 
181cdf0e10cSrcweir     //---------------------------------------------------------------------
getInfoHelper()182cdf0e10cSrcweir     ::cppu::IPropertyArrayHelper& SAL_CALL OCommonPicker::getInfoHelper()
183cdf0e10cSrcweir     {
184cdf0e10cSrcweir         return *const_cast< OCommonPicker* >( this )->getArrayHelper();
185cdf0e10cSrcweir     }
186cdf0e10cSrcweir 
187cdf0e10cSrcweir     //---------------------------------------------------------------------
getPropertySetInfo()188cdf0e10cSrcweir     Reference< XPropertySetInfo > SAL_CALL OCommonPicker::getPropertySetInfo(  ) throw(RuntimeException)
189cdf0e10cSrcweir     {
190cdf0e10cSrcweir         return ::cppu::OPropertySetHelper::createPropertySetInfo( getInfoHelper() );
191cdf0e10cSrcweir     }
192cdf0e10cSrcweir 
193cdf0e10cSrcweir     //---------------------------------------------------------------------
setFastPropertyValue_NoBroadcast(sal_Int32 _nHandle,const Any & _rValue)194cdf0e10cSrcweir     void SAL_CALL OCommonPicker::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const Any& _rValue ) throw (Exception)
195cdf0e10cSrcweir     {
196cdf0e10cSrcweir         OPropertyContainer::setFastPropertyValue_NoBroadcast( _nHandle, _rValue );
197cdf0e10cSrcweir 
198cdf0e10cSrcweir         // if the HelpURL changed, forward this to the dialog
199cdf0e10cSrcweir         if ( PROPERTY_ID_HELPURL == _nHandle )
200cdf0e10cSrcweir             if ( m_pDlg )
201cdf0e10cSrcweir                 OControlAccess::setHelpURL( m_pDlg, m_sHelpURL, sal_False );
202cdf0e10cSrcweir     }
203cdf0e10cSrcweir 
204cdf0e10cSrcweir 
205cdf0e10cSrcweir     //---------------------------------------------------------------------
createPicker()206cdf0e10cSrcweir     sal_Bool OCommonPicker::createPicker()
207cdf0e10cSrcweir     {
208cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
209cdf0e10cSrcweir 
210cdf0e10cSrcweir         if ( !m_pDlg )
211cdf0e10cSrcweir         {
212cdf0e10cSrcweir             m_pDlg = implCreateDialog( VCLUnoHelper::GetWindow( m_xDialogParent ) );
213cdf0e10cSrcweir             DBG_ASSERT( m_pDlg, "OCommonPicker::createPicker: invalid dialog returned!" );
214cdf0e10cSrcweir 
215cdf0e10cSrcweir             if ( m_pDlg )
216cdf0e10cSrcweir             {
217cdf0e10cSrcweir                 // synchronize the help id of the dialog with out help URL property
218cdf0e10cSrcweir                 if ( m_sHelpURL.getLength() )
219cdf0e10cSrcweir                 {   // somebody already set the help URL while we had no dialog yet
220cdf0e10cSrcweir                     OControlAccess::setHelpURL( m_pDlg, m_sHelpURL, sal_False );
221cdf0e10cSrcweir                 }
222cdf0e10cSrcweir                 else
223cdf0e10cSrcweir                 {
224cdf0e10cSrcweir                     m_sHelpURL = OControlAccess::getHelpURL( m_pDlg, sal_False );
225cdf0e10cSrcweir                 }
226cdf0e10cSrcweir 
227cdf0e10cSrcweir                 m_xWindow = VCLUnoHelper::GetInterface( m_pDlg );
228cdf0e10cSrcweir 
229cdf0e10cSrcweir                 // add as event listener to the window
230cdf0e10cSrcweir                 Reference< XComponent > xWindowComp( m_xWindow, UNO_QUERY );
231cdf0e10cSrcweir                 OSL_ENSURE( xWindowComp.is(), "OCommonPicker::createFileDialog: invalid window component!" );
232cdf0e10cSrcweir                 if ( xWindowComp.is() )
233cdf0e10cSrcweir                 {
234cdf0e10cSrcweir                     m_xWindowListenerAdapter = new OWeakEventListenerAdapter( this, xWindowComp );
235cdf0e10cSrcweir                         // the adapter will add itself as listener, and forward notifications
236cdf0e10cSrcweir                 }
237cdf0e10cSrcweir 
238cdf0e10cSrcweir                 // _and_ add as event listener to the parent - in case the parent is destroyed
239cdf0e10cSrcweir                 // before we are disposed, our disposal would access dead VCL windows then ....
240cdf0e10cSrcweir                 m_xDialogParent = VCLUnoHelper::GetInterface( m_pDlg->GetParent() );
241cdf0e10cSrcweir                 xWindowComp = xWindowComp.query( m_xDialogParent );
242cdf0e10cSrcweir                 OSL_ENSURE( xWindowComp.is() || !m_pDlg->GetParent(), "OCommonPicker::createFileDialog: invalid window component (the parent this time)!" );
243cdf0e10cSrcweir                 if ( xWindowComp.is() )
244cdf0e10cSrcweir                 {
245cdf0e10cSrcweir                     m_xParentListenerAdapter = new OWeakEventListenerAdapter( this, xWindowComp );
246cdf0e10cSrcweir                         // the adapter will add itself as listener, and forward notifications
247cdf0e10cSrcweir                 }
248cdf0e10cSrcweir             }
249cdf0e10cSrcweir         }
250cdf0e10cSrcweir 
251cdf0e10cSrcweir         return NULL != m_pDlg;
252cdf0e10cSrcweir     }
253cdf0e10cSrcweir 
254cdf0e10cSrcweir     //---------------------------------------------------------------------
255cdf0e10cSrcweir     // XControlAccess functions
256cdf0e10cSrcweir     //---------------------------------------------------------------------
setControlProperty(const::rtl::OUString & aControlName,const::rtl::OUString & aControlProperty,const Any & aValue)257cdf0e10cSrcweir     void SAL_CALL OCommonPicker::setControlProperty( const ::rtl::OUString& aControlName, const ::rtl::OUString& aControlProperty, const Any& aValue ) throw (IllegalArgumentException, RuntimeException)
258cdf0e10cSrcweir     {
259cdf0e10cSrcweir         checkAlive();
260cdf0e10cSrcweir 
261cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
262cdf0e10cSrcweir         if ( createPicker() )
263cdf0e10cSrcweir         {
264cdf0e10cSrcweir             ::svt::OControlAccess aAccess( m_pDlg, m_pDlg->GetView() );
265cdf0e10cSrcweir             aAccess.setControlProperty( aControlName, aControlProperty, aValue );
266cdf0e10cSrcweir         }
267cdf0e10cSrcweir     }
268cdf0e10cSrcweir 
269cdf0e10cSrcweir     //---------------------------------------------------------------------
getControlProperty(const::rtl::OUString & aControlName,const::rtl::OUString & aControlProperty)270cdf0e10cSrcweir     Any SAL_CALL OCommonPicker::getControlProperty( const ::rtl::OUString& aControlName, const ::rtl::OUString& aControlProperty ) throw (IllegalArgumentException, RuntimeException)
271cdf0e10cSrcweir     {
272cdf0e10cSrcweir         checkAlive();
273cdf0e10cSrcweir 
274cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
275cdf0e10cSrcweir         if ( createPicker() )
276cdf0e10cSrcweir         {
277cdf0e10cSrcweir             ::svt::OControlAccess aAccess( m_pDlg, m_pDlg->GetView() );
278cdf0e10cSrcweir             return aAccess.getControlProperty( aControlName, aControlProperty );
279cdf0e10cSrcweir         }
280cdf0e10cSrcweir 
281cdf0e10cSrcweir         return Any();
282cdf0e10cSrcweir     }
283cdf0e10cSrcweir 
284cdf0e10cSrcweir     //---------------------------------------------------------------------
285cdf0e10cSrcweir     // XControlInformation functions
286cdf0e10cSrcweir     //---------------------------------------------------------------------
getSupportedControls()287cdf0e10cSrcweir     Sequence< ::rtl::OUString > SAL_CALL OCommonPicker::getSupportedControls(  ) throw (RuntimeException)
288cdf0e10cSrcweir     {
289cdf0e10cSrcweir         checkAlive();
290cdf0e10cSrcweir 
291cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
292cdf0e10cSrcweir         if ( createPicker() )
293cdf0e10cSrcweir         {
294cdf0e10cSrcweir             ::svt::OControlAccess aAccess( m_pDlg, m_pDlg->GetView() );
295cdf0e10cSrcweir             return aAccess.getSupportedControls( );
296cdf0e10cSrcweir         }
297cdf0e10cSrcweir 
298cdf0e10cSrcweir         return Sequence< ::rtl::OUString >();
299cdf0e10cSrcweir     }
300cdf0e10cSrcweir 
301cdf0e10cSrcweir     //---------------------------------------------------------------------
isControlSupported(const::rtl::OUString & aControlName)302cdf0e10cSrcweir     sal_Bool SAL_CALL OCommonPicker::isControlSupported( const ::rtl::OUString& aControlName ) throw (RuntimeException)
303cdf0e10cSrcweir     {
304cdf0e10cSrcweir         checkAlive();
305cdf0e10cSrcweir 
306cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
307cdf0e10cSrcweir         if ( createPicker() )
308cdf0e10cSrcweir         {
309cdf0e10cSrcweir             ::svt::OControlAccess aAccess( m_pDlg, m_pDlg->GetView() );
310cdf0e10cSrcweir             return aAccess.isControlSupported( aControlName );
311cdf0e10cSrcweir         }
312cdf0e10cSrcweir 
313cdf0e10cSrcweir         return sal_False;
314cdf0e10cSrcweir     }
315cdf0e10cSrcweir 
316cdf0e10cSrcweir     //---------------------------------------------------------------------
getSupportedControlProperties(const::rtl::OUString & aControlName)317cdf0e10cSrcweir     Sequence< ::rtl::OUString > SAL_CALL OCommonPicker::getSupportedControlProperties( const ::rtl::OUString& aControlName ) throw (IllegalArgumentException, RuntimeException)
318cdf0e10cSrcweir     {
319cdf0e10cSrcweir         checkAlive();
320cdf0e10cSrcweir 
321cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
322cdf0e10cSrcweir         if ( createPicker() )
323cdf0e10cSrcweir         {
324cdf0e10cSrcweir             ::svt::OControlAccess aAccess( m_pDlg, m_pDlg->GetView() );
325cdf0e10cSrcweir             return aAccess.getSupportedControlProperties( aControlName );
326cdf0e10cSrcweir         }
327cdf0e10cSrcweir 
328cdf0e10cSrcweir         return Sequence< ::rtl::OUString >();
329cdf0e10cSrcweir     }
330cdf0e10cSrcweir 
331cdf0e10cSrcweir     //---------------------------------------------------------------------
isControlPropertySupported(const::rtl::OUString & aControlName,const::rtl::OUString & aControlProperty)332cdf0e10cSrcweir     sal_Bool SAL_CALL OCommonPicker::isControlPropertySupported( const ::rtl::OUString& aControlName, const ::rtl::OUString& aControlProperty ) throw (IllegalArgumentException, RuntimeException)
333cdf0e10cSrcweir     {
334cdf0e10cSrcweir         checkAlive();
335cdf0e10cSrcweir 
336cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
337cdf0e10cSrcweir         if ( createPicker() )
338cdf0e10cSrcweir         {
339cdf0e10cSrcweir             ::svt::OControlAccess aAccess( m_pDlg, m_pDlg->GetView() );
340cdf0e10cSrcweir             return aAccess.isControlPropertySupported( aControlName, aControlProperty );
341cdf0e10cSrcweir         }
342cdf0e10cSrcweir 
343cdf0e10cSrcweir         return sal_False;
344cdf0e10cSrcweir     }
345cdf0e10cSrcweir 
346cdf0e10cSrcweir     //---------------------------------------------------------------------
347cdf0e10cSrcweir     // XExecutableDialog functions
348cdf0e10cSrcweir     //---------------------------------------------------------------------
setTitle(const rtl::OUString & _rTitle)349cdf0e10cSrcweir     void SAL_CALL OCommonPicker::setTitle( const rtl::OUString& _rTitle ) throw( RuntimeException )
350cdf0e10cSrcweir     {
351cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
352cdf0e10cSrcweir         m_aTitle = _rTitle;
353cdf0e10cSrcweir     }
354cdf0e10cSrcweir 
355cdf0e10cSrcweir     //---------------------------------------------------------------------
execute()356cdf0e10cSrcweir     sal_Int16 OCommonPicker::execute() throw (RuntimeException)
357cdf0e10cSrcweir     {
358cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
359cdf0e10cSrcweir 
360cdf0e10cSrcweir         prepareDialog();
361cdf0e10cSrcweir 
362cdf0e10cSrcweir         {
363cdf0e10cSrcweir             ::osl::MutexGuard aOwnGuard( m_aMutex );
364cdf0e10cSrcweir             m_bExecuting = sal_True;
365cdf0e10cSrcweir         }
366cdf0e10cSrcweir         sal_Int16 nResult = implExecutePicker();
367cdf0e10cSrcweir         {
368cdf0e10cSrcweir             ::osl::MutexGuard aOwnGuard( m_aMutex );
369cdf0e10cSrcweir             m_bExecuting = sal_False;
370cdf0e10cSrcweir         }
371cdf0e10cSrcweir 
372cdf0e10cSrcweir         return nResult;
373cdf0e10cSrcweir     }
374cdf0e10cSrcweir 
375cdf0e10cSrcweir     //---------------------------------------------------------------------
376cdf0e10cSrcweir     // XCancellable functions
377cdf0e10cSrcweir     //---------------------------------------------------------------------
cancel()378cdf0e10cSrcweir     void SAL_CALL OCommonPicker::cancel(  ) throw (RuntimeException)
379cdf0e10cSrcweir     {
380cdf0e10cSrcweir         {
381cdf0e10cSrcweir             ::osl::MutexGuard aGuard( m_aMutex );
382cdf0e10cSrcweir             if ( m_nCancelEvent )
383cdf0e10cSrcweir                 // nothing to do - the event for cancelling the dialog is already on the way
384cdf0e10cSrcweir                 return;
385cdf0e10cSrcweir         }
386cdf0e10cSrcweir 
387cdf0e10cSrcweir         // The thread which executes our dialog has locked the solar mutex for
388cdf0e10cSrcweir         // sure. Cancelling the dialog should be done with a locked solar mutex, too.
389cdf0e10cSrcweir         // Thus we post ourself a message for cancelling the dialog. This way, the message
390cdf0e10cSrcweir         // is either handled in the thread which opened the dialog (which may even be
391cdf0e10cSrcweir         // this thread here), or, if no dialog is open, in the thread doing scheduling
392cdf0e10cSrcweir         // currently. Both is okay for us ....
393cdf0e10cSrcweir         //
394cdf0e10cSrcweir         // Note that we could do check if we are really executing the dialog currently.
395cdf0e10cSrcweir         // but the information would be potentially obsolete at the moment our event
396cdf0e10cSrcweir         // arrives, so we need to check it there, anyway ...
397cdf0e10cSrcweir         m_nCancelEvent = Application::PostUserEvent( LINK( this, OCommonPicker, OnCancelPicker ) );
398cdf0e10cSrcweir     }
399cdf0e10cSrcweir 
400cdf0e10cSrcweir     //---------------------------------------------------------------------
IMPL_LINK(OCommonPicker,OnCancelPicker,void *,EMPTYARG)401cdf0e10cSrcweir     IMPL_LINK( OCommonPicker, OnCancelPicker, void*, EMPTYARG )
402cdf0e10cSrcweir     {
403cdf0e10cSrcweir         // By definition, the solar mutex is locked when we arrive here. Note that this
404cdf0e10cSrcweir         // is important, as for instance the consistency of m_pDlg depends on this mutex.
405cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
406cdf0e10cSrcweir         m_nCancelEvent = 0;
407cdf0e10cSrcweir 
408cdf0e10cSrcweir         if ( !m_bExecuting )
409cdf0e10cSrcweir             // nothing to do. This may be because the dialog was cancelled after our cancel method
410cdf0e10cSrcweir             // posted this async event, or because somebody called cancel without the dialog
411cdf0e10cSrcweir             // being executed at this time.
412cdf0e10cSrcweir             return 0;
413cdf0e10cSrcweir 
414cdf0e10cSrcweir         OSL_ENSURE( getDialog(), "OCommonPicker::OnCancelPicker: executing, but no dialog!" );
415cdf0e10cSrcweir         if ( getDialog() )
416cdf0e10cSrcweir             getDialog()->EndDialog( RET_CANCEL );
417cdf0e10cSrcweir 
418cdf0e10cSrcweir         return 0L;
419cdf0e10cSrcweir     }
420cdf0e10cSrcweir 
421cdf0e10cSrcweir     //------------------------------------------------------------------------------------
422cdf0e10cSrcweir     // XInitialization functions
423cdf0e10cSrcweir     //------------------------------------------------------------------------------------
initialize(const Sequence<Any> & _rArguments)424cdf0e10cSrcweir     void SAL_CALL OCommonPicker::initialize( const Sequence< Any >& _rArguments )
425cdf0e10cSrcweir         throw ( Exception, RuntimeException )
426cdf0e10cSrcweir     {
427cdf0e10cSrcweir         checkAlive();
428cdf0e10cSrcweir 
429cdf0e10cSrcweir         ::rtl::OUString sSettingName;
430cdf0e10cSrcweir         Any             aSettingValue;
431cdf0e10cSrcweir 
432cdf0e10cSrcweir         PropertyValue   aPropArg;
433cdf0e10cSrcweir         NamedValue      aPairArg;
434cdf0e10cSrcweir 
435cdf0e10cSrcweir 
436cdf0e10cSrcweir         const Any* pArguments       = _rArguments.getConstArray();
437cdf0e10cSrcweir         const Any* pArgumentsEnd    = _rArguments.getConstArray() + _rArguments.getLength();
438cdf0e10cSrcweir         for (   const Any* pArgument = pArguments;
439cdf0e10cSrcweir                 pArgument != pArgumentsEnd;
440cdf0e10cSrcweir                 ++pArgument
441cdf0e10cSrcweir             )
442cdf0e10cSrcweir         {
443cdf0e10cSrcweir             if ( *pArgument >>= aPropArg )
444cdf0e10cSrcweir             {
445cdf0e10cSrcweir                 if ( aPropArg.Name.getLength() <= 0)
446cdf0e10cSrcweir                     continue;
447cdf0e10cSrcweir 
448cdf0e10cSrcweir                 sSettingName = aPropArg.Name;
449cdf0e10cSrcweir                 aSettingValue = aPropArg.Value;
450cdf0e10cSrcweir             }
451cdf0e10cSrcweir             else if ( *pArgument >>= aPairArg )
452cdf0e10cSrcweir             {
453cdf0e10cSrcweir                 if ( aPairArg.Name.getLength() <= 0)
454cdf0e10cSrcweir                     continue;
455cdf0e10cSrcweir 
456cdf0e10cSrcweir                 sSettingName = aPairArg.Name;
457cdf0e10cSrcweir                 aSettingValue = aPairArg.Value;
458cdf0e10cSrcweir 
459cdf0e10cSrcweir 
460cdf0e10cSrcweir             }
461cdf0e10cSrcweir             else
462cdf0e10cSrcweir             {
463cdf0e10cSrcweir                 DBG_ERROR(
464cdf0e10cSrcweir                     (   ::rtl::OString( "OCommonPicker::initialize: unknown argument type at position " )
465cdf0e10cSrcweir                     +=  ::rtl::OString::valueOf( (sal_Int32)( pArguments - _rArguments.getConstArray() ) )
466cdf0e10cSrcweir                     ).getStr()
467cdf0e10cSrcweir                 );
468cdf0e10cSrcweir                 continue;
469cdf0e10cSrcweir             }
470cdf0e10cSrcweir 
471cdf0e10cSrcweir #ifdef DBG_UTIL
472cdf0e10cSrcweir             sal_Bool bKnownSetting =
473cdf0e10cSrcweir #endif
474cdf0e10cSrcweir             implHandleInitializationArgument( sSettingName, aSettingValue );
475cdf0e10cSrcweir             DBG_ASSERT( bKnownSetting,
476cdf0e10cSrcweir                 (   ::rtl::OString( "OCommonPicker::initialize: unknown argument \"" )
477cdf0e10cSrcweir                 +=  ::rtl::OString( sSettingName.getStr(), sSettingName.getLength(), osl_getThreadTextEncoding() )
478cdf0e10cSrcweir                 +=  ::rtl::OString( "\"!" )
479cdf0e10cSrcweir                 ).getStr()
480cdf0e10cSrcweir             );
481cdf0e10cSrcweir         }
482cdf0e10cSrcweir     }
483cdf0e10cSrcweir 
484cdf0e10cSrcweir     //---------------------------------------------------------------------
implHandleInitializationArgument(const::rtl::OUString & _rName,const Any & _rValue)485cdf0e10cSrcweir     sal_Bool OCommonPicker::implHandleInitializationArgument( const ::rtl::OUString& _rName, const Any& _rValue ) SAL_THROW( ( Exception, RuntimeException ) )
486cdf0e10cSrcweir     {
487cdf0e10cSrcweir         sal_Bool bKnown = sal_True;
488cdf0e10cSrcweir         if ( _rName.equalsAscii( "ParentWindow" ) )
489cdf0e10cSrcweir         {
490cdf0e10cSrcweir             m_xDialogParent.clear();
491cdf0e10cSrcweir             OSL_VERIFY( _rValue >>= m_xDialogParent );
492cdf0e10cSrcweir             OSL_ENSURE( VCLUnoHelper::GetWindow( m_xDialogParent ), "OCommonPicker::implHandleInitializationArgument: invalid parent window given!" );
493cdf0e10cSrcweir         }
494cdf0e10cSrcweir         else
495cdf0e10cSrcweir             bKnown = sal_False;
496cdf0e10cSrcweir         return bKnown;
497cdf0e10cSrcweir     }
498cdf0e10cSrcweir 
499cdf0e10cSrcweir //.........................................................................
500cdf0e10cSrcweir }   // namespace svt
501cdf0e10cSrcweir //.........................................................................
502