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 #ifndef SVTOOLS_COMMONPICKER_HXX
25 #define SVTOOLS_COMMONPICKER_HXX
26 
27 #include <cppuhelper/compbase5.hxx>
28 #include <com/sun/star/ui/dialogs/XControlInformation.hpp>
29 #include <com/sun/star/ui/dialogs/XControlAccess.hpp>
30 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
31 #include <com/sun/star/lang/DisposedException.hpp>
32 #include <com/sun/star/awt/XWindow.hpp>
33 #include <com/sun/star/util/XCancellable.hpp>
34 #include <com/sun/star/lang/XInitialization.hpp>
35 #include <comphelper/broadcasthelper.hxx>
36 #include <comphelper/propertycontainer.hxx>
37 #include <comphelper/proparrhlp.hxx>
38 #include <comphelper/uno3.hxx>
39 #include <tools/link.hxx>
40 
41 class SvtFileDialog;
42 class Window;
43 
44 namespace comphelper
45 {
46 	class OWeakEventListenerAdapter;
47 }
48 
49 //.........................................................................
50 namespace svt
51 {
52 //.........................................................................
53 
54 	typedef ::cppu::WeakComponentImplHelper5	<	::com::sun::star::ui::dialogs::XControlAccess
55 												,	::com::sun::star::ui::dialogs::XControlInformation
56 												,	::com::sun::star::lang::XEventListener
57 												,	::com::sun::star::util::XCancellable
58 												,	::com::sun::star::lang::XInitialization
59 												>	OCommonPicker_Base;
60 	/** implements common functionality for the 2 UNO picker components
61 	*/
62 	class OCommonPicker
63 					:public ::comphelper::OBaseMutex
64 					,public OCommonPicker_Base
65 					,public ::comphelper::OPropertyContainer
66 					,public ::comphelper::OPropertyArrayUsageHelper< OCommonPicker >
67 	{
68 	private:
69 		::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >	m_xORB;
70 
71 		// <properties>
72 		::rtl::OUString														m_sHelpURL;
73 		::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >	m_xWindow;
74 		// </properties>
75 
76 		SvtFileDialog*		m_pDlg;
77 		sal_uInt32			m_nCancelEvent;
78 		sal_Bool			m_bExecuting;
79 
80 		::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >	m_xDialogParent;
81 
82 		::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >	m_xWindowListenerAdapter;
83 		::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >	m_xParentListenerAdapter;
84 
85 	protected:
86 		::rtl::OUString		m_aTitle;
87 		::rtl::OUString		m_aDisplayDirectory;
88 
89 	protected:
getDialog()90 		inline	SvtFileDialog*	getDialog() { return m_pDlg; }
91 
GetBroadcastHelper() const92 		inline const	::cppu::OBroadcastHelper&	GetBroadcastHelper() const	{ return OCommonPicker_Base::rBHelper; }
GetBroadcastHelper()93 		inline			::cppu::OBroadcastHelper&	GetBroadcastHelper()		{ return OCommonPicker_Base::rBHelper; }
94 
95 	public:
96 		OCommonPicker( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory );
97 
98 	protected:
99 		virtual ~OCommonPicker();
100 
101 		// overridables
102 
103 		// will be called with locked SolarMutex
104 		virtual SvtFileDialog*	implCreateDialog( Window* _pParent ) = 0;
105 		virtual	sal_Int16		implExecutePicker( ) = 0;
106 			// do NOT override XExecutableDialog::execute! We need to do some stuff there ourself ...
107 
108 	protected:
109 		//------------------------------------------------------------------------------------
110 		// disambiguate XInterface
111 		//------------------------------------------------------------------------------------
112 		DECLARE_XINTERFACE( )
113 
114 		//------------------------------------------------------------------------------------
115 		// disambiguate XTypeProvider
116 		//------------------------------------------------------------------------------------
117 		DECLARE_XTYPEPROVIDER( )
118 
119 		//------------------------------------------------------------------------------------
120 		// ComponentHelper/XComponent
121 		//------------------------------------------------------------------------------------
122 		virtual void SAL_CALL disposing();
123 
124 		//------------------------------------------------------------------------------------
125 		// XEventListner
126 		//------------------------------------------------------------------------------------
127 		virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
128 
129 		//------------------------------------------------------------------------------------
130 		// property set related methods
131 		//------------------------------------------------------------------------------------
132 
133 		// XPropertySet pure methods
134 		virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException);
135 		// OPropertySetHelper pure methods
136 		virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper();
137 		// OPropertyArrayUsageHelper pure methods
138 		virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const;
139 
140 		// OPropertySetHelper overridden methods
141 		virtual void SAL_CALL setFastPropertyValue_NoBroadcast(
142 				sal_Int32 _nHandle, const ::com::sun::star::uno::Any& _rValue ) throw (::com::sun::star::uno::Exception);
143 
144 		//------------------------------------------------------------------------------------
145 		// XExecutableDialog functions
146 		//------------------------------------------------------------------------------------
147 		virtual void SAL_CALL 			setTitle( const ::rtl::OUString& _rTitle ) throw( ::com::sun::star::uno::RuntimeException );
148 		virtual sal_Int16 SAL_CALL 		execute() throw( ::com::sun::star::uno::RuntimeException );
149 
150 		//------------------------------------------------------------------------------------
151 		// XControlAccess functions
152 		//------------------------------------------------------------------------------------
153 		virtual void SAL_CALL setControlProperty( const ::rtl::OUString& aControlName, const ::rtl::OUString& aControlProperty, const ::com::sun::star::uno::Any& aValue ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
154 		virtual ::com::sun::star::uno::Any SAL_CALL getControlProperty( const ::rtl::OUString& aControlName, const ::rtl::OUString& aControlProperty ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
155 
156 		//------------------------------------------------------------------------------------
157 		// XControlInformation functions
158 		//------------------------------------------------------------------------------------
159 		virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedControls(  ) throw (::com::sun::star::uno::RuntimeException);
160 		virtual sal_Bool SAL_CALL isControlSupported( const ::rtl::OUString& aControlName ) throw (::com::sun::star::uno::RuntimeException);
161 		virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedControlProperties( const ::rtl::OUString& aControlName ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
162 		virtual sal_Bool SAL_CALL isControlPropertySupported( const ::rtl::OUString& aControlName, const ::rtl::OUString& aControlProperty ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
163 
164 		//------------------------------------------------------------------------------------
165 		// XCancellable functions
166 		//------------------------------------------------------------------------------------
167 		virtual void SAL_CALL cancel(  ) throw (::com::sun::star::uno::RuntimeException);
168 
169 		//------------------------------------------------------------------------------------
170 		// XInitialization functions
171 		//------------------------------------------------------------------------------------
172 
173 		virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw ( ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException );
174 
175 		//------------------------------------------------------------------------------------
176 		// misc
177 		//------------------------------------------------------------------------------------
178 		void checkAlive() const SAL_THROW( (::com::sun::star::lang::DisposedException) );
179 
180         void prepareDialog();
181 
182 	protected:
183 				sal_Bool	createPicker();
184 
185 		/** handle a single argument from the XInitialization::initialize method
186 
187 			@return <TRUE/> if the argument could be handled
188 		*/
189 		virtual	sal_Bool	implHandleInitializationArgument(
190 								const ::rtl::OUString& _rName,
191 								const ::com::sun::star::uno::Any& _rValue
192 							)
193 							SAL_THROW( ( ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException ) );
194 
195 	private:
196 		void		stopWindowListening();
197 
198 		DECL_LINK( OnCancelPicker, void* );
199 	};
200 //.........................................................................
201 }	// namespace svt
202 //.........................................................................
203 
204 #endif // SVTOOLS_COMMONPICKER_HXX
205 
206