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