xref: /trunk/main/chart2/source/controller/dialogs/dlg_CreationWizard_UNO.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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_chartcontroller.hxx"
26 
27 #include "dlg_CreationWizard_UNO.hxx"
28 #include "dlg_CreationWizard.hxx"
29 #include "macros.hxx"
30 #include "servicenames.hxx"
31 #include "ContainerHelper.hxx"
32 #include "TimerTriggeredControllerLock.hxx"
33 #include <osl/mutex.hxx>
34 #include <vos/mutex.hxx>
35 // header for class Application
36 #include <vcl/svapp.hxx>
37 #include <toolkit/awt/vclxwindow.hxx>
38 // header for define RET_CANCEL
39 #include <vcl/msgbox.hxx>
40 // header for class OImplementationId
41 #include <cppuhelper/typeprovider.hxx>
42 #include <com/sun/star/awt/Point.hpp>
43 #include <com/sun/star/awt/Size.hpp>
44 #include <com/sun/star/beans/PropertyValue.hpp>
45 #include <com/sun/star/frame/XDesktop.hpp>
46 
47 //.............................................................................
48 namespace chart
49 {
50 //.............................................................................
51 using namespace ::com::sun::star;
52 
CreationWizardUnoDlg(const uno::Reference<uno::XComponentContext> & xContext)53 CreationWizardUnoDlg::CreationWizardUnoDlg( const uno::Reference< uno::XComponentContext >& xContext )
54                     : OComponentHelper( m_aMutex )
55                     , m_xChartModel( 0 )
56                     , m_xCC( xContext )
57                     , m_xParentWindow( 0 )
58                     , m_pDialog( 0 )
59                     , m_bUnlockControllersOnExecute(false)
60 {
61     uno::Reference< frame::XDesktop > xDesktop(
62         m_xCC->getServiceManager()->createInstanceWithContext(
63             C2U( "com.sun.star.frame.Desktop" ), m_xCC ), uno::UNO_QUERY );
64     if( xDesktop.is() )
65     {
66         uno::Reference< frame::XTerminateListener > xListener( this );
67         xDesktop->addTerminateListener( xListener );
68     }
69 }
~CreationWizardUnoDlg()70 CreationWizardUnoDlg::~CreationWizardUnoDlg()
71 {
72     ::vos::OGuard aSolarGuard( Application::GetSolarMutex());
73     if( m_pDialog )
74     {
75         delete m_pDialog;
76         m_pDialog = 0;
77     }
78 }
79 //-------------------------------------------------------------------------
80 // lang::XServiceInfo
APPHELPER_XSERVICEINFO_IMPL(CreationWizardUnoDlg,CHART_WIZARD_DIALOG_SERVICE_IMPLEMENTATION_NAME)81 APPHELPER_XSERVICEINFO_IMPL(CreationWizardUnoDlg,CHART_WIZARD_DIALOG_SERVICE_IMPLEMENTATION_NAME)
82 
83     uno::Sequence< rtl::OUString > CreationWizardUnoDlg
84 ::getSupportedServiceNames_Static()
85 {
86     uno::Sequence< rtl::OUString > aSNS( 1 );
87     aSNS.getArray()[ 0 ] = CHART_WIZARD_DIALOG_SERVICE_NAME;
88     return aSNS;
89 }
90 
91 //-------------------------------------------------------------------------
92 // XInterface
queryInterface(const uno::Type & aType)93 uno::Any SAL_CALL CreationWizardUnoDlg::queryInterface( const uno::Type& aType )
94 {
95     return OComponentHelper::queryInterface( aType );
96 }
acquire()97 void SAL_CALL CreationWizardUnoDlg::acquire() throw ()
98 {
99     OComponentHelper::acquire();
100 }
release()101 void SAL_CALL CreationWizardUnoDlg::release() throw ()
102 {
103     OComponentHelper::release();
104 }
queryAggregation(uno::Type const & rType)105 uno::Any SAL_CALL CreationWizardUnoDlg::queryAggregation( uno::Type const & rType )
106 {
107     if (rType == ::getCppuType( (uno::Reference< ui::dialogs::XExecutableDialog > const *)0 ))
108     {
109         void * p = static_cast< ui::dialogs::XExecutableDialog * >( this );
110         return uno::Any( &p, rType );
111     }
112     else if (rType == ::getCppuType( (uno::Reference< lang::XServiceInfo > const *)0 ))
113     {
114         void * p = static_cast< lang::XTypeProvider * >( this );
115         return uno::Any( &p, rType );
116     }
117     else if (rType == ::getCppuType( (uno::Reference< lang::XInitialization > const *)0 ))
118     {
119         void * p = static_cast< lang::XInitialization * >( this );
120         return uno::Any( &p, rType );
121     }
122     else if (rType == ::getCppuType( (uno::Reference< frame::XTerminateListener > const *)0 ))
123     {
124         void * p = static_cast< frame::XTerminateListener * >( this );
125         return uno::Any( &p, rType );
126     }
127     else if (rType == ::getCppuType( (uno::Reference< beans::XPropertySet > const *)0 ))
128     {
129         void * p = static_cast< beans::XPropertySet * >( this );
130         return uno::Any( &p, rType );
131     }
132     return OComponentHelper::queryAggregation( rType );
133 }
134 
135 //-------------------------------------------------------------------------
136 #define LCL_CPPUTYPE(t) (::getCppuType( reinterpret_cast< const uno::Reference<t> *>(0)))
137 
getTypes()138 uno::Sequence< uno::Type > CreationWizardUnoDlg::getTypes()
139 {
140     static uno::Sequence< uno::Type > aTypeList;
141 
142     // /--
143     ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
144     if( !aTypeList.getLength() )
145     {
146         ::std::vector< uno::Type > aTypes;
147         aTypes.push_back( LCL_CPPUTYPE( lang::XComponent ));
148         aTypes.push_back( LCL_CPPUTYPE( lang::XTypeProvider ));
149         aTypes.push_back( LCL_CPPUTYPE( uno::XAggregation ));
150         aTypes.push_back( LCL_CPPUTYPE( uno::XWeak ));
151         aTypes.push_back( LCL_CPPUTYPE( lang::XServiceInfo ));
152         aTypes.push_back( LCL_CPPUTYPE( lang::XInitialization ));
153         aTypes.push_back( LCL_CPPUTYPE( frame::XTerminateListener ));
154         aTypes.push_back( LCL_CPPUTYPE( ui::dialogs::XExecutableDialog ));
155         aTypes.push_back( LCL_CPPUTYPE( beans::XPropertySet ));
156         aTypeList = ::chart::ContainerHelper::ContainerToSequence( aTypes );
157     }
158 
159     return aTypeList;
160     // \--
161 }
getImplementationId(void)162 uno::Sequence< sal_Int8 > SAL_CALL CreationWizardUnoDlg::getImplementationId( void )
163 {
164     static uno::Sequence< sal_Int8 > aId;
165     if( aId.getLength() == 0 )
166     {
167         aId.realloc( 16 );
168         rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True );
169     }
170     return aId;
171 }
172 
173 //-------------------------------------------------------------------------
174 
175 // XTerminateListener
queryTermination(const lang::EventObject &)176 void SAL_CALL CreationWizardUnoDlg::queryTermination( const lang::EventObject& /*Event*/ )
177 {
178     ::vos::OGuard aSolarGuard( Application::GetSolarMutex());
179 
180     // we will never give a veto here
181     if( m_pDialog && !m_pDialog->isClosable() )
182     {
183         m_pDialog->ToTop();
184         throw frame::TerminationVetoException();
185     }
186 }
187 
188 //-------------------------------------------------------------------------
189 
notifyTermination(const lang::EventObject &)190 void SAL_CALL CreationWizardUnoDlg::notifyTermination( const lang::EventObject& /*Event*/ )
191 {
192     // we are going down, so dispose us!
193     dispose();
194 }
195 
disposing(const lang::EventObject &)196 void SAL_CALL CreationWizardUnoDlg::disposing( const lang::EventObject& /*Source*/ )
197 {
198     //Listener should deregister himself and release all references to the closing object.
199 }
200 
201 //-------------------------------------------------------------------------
setTitle(const::rtl::OUString &)202 void SAL_CALL CreationWizardUnoDlg::setTitle( const ::rtl::OUString& /*rTitle*/ )
203 {
204 }
205 //-------------------------------------------------------------------------
createDialogOnDemand()206 void CreationWizardUnoDlg::createDialogOnDemand()
207 {
208     ::vos::OGuard aSolarGuard( Application::GetSolarMutex());
209     if( !m_pDialog )
210     {
211         Window* pParent = NULL;
212         if( !m_xParentWindow.is() && m_xChartModel.is() )
213         {
214             uno::Reference< frame::XController > xController(
215                 m_xChartModel->getCurrentController() );
216             if( xController.is() )
217             {
218                 uno::Reference< frame::XFrame > xFrame(
219                     xController->getFrame() );
220                 if(xFrame.is())
221                     m_xParentWindow = xFrame->getContainerWindow();
222             }
223         }
224         if( m_xParentWindow.is() )
225         {
226             VCLXWindow* pImplementation = VCLXWindow::GetImplementation(m_xParentWindow);
227             if (pImplementation)
228                 pParent = pImplementation->GetWindow();
229         }
230         uno::Reference< XComponent > xComp( this );
231         if( m_xChartModel.is() )
232         {
233             m_pDialog = new CreationWizard( pParent, m_xChartModel, m_xCC );
234             m_pDialog->AddEventListener( LINK( this, CreationWizardUnoDlg, DialogEventHdl ) );
235         }
236     }
237 }
238 //-------------------------------------------------------------------------
IMPL_LINK(CreationWizardUnoDlg,DialogEventHdl,VclWindowEvent *,pEvent)239 IMPL_LINK( CreationWizardUnoDlg, DialogEventHdl, VclWindowEvent*, pEvent )
240 {
241     if(pEvent && (pEvent->GetId() == VCLEVENT_OBJECT_DYING) )
242         m_pDialog = 0;//avoid duplicate destruction of m_pDialog
243     return 0;
244 }
245 
246 //-------------------------------------------------------------------------
execute()247 sal_Int16 SAL_CALL CreationWizardUnoDlg::execute(  )
248 {
249     sal_Int16 nRet = RET_CANCEL;
250     {
251         ::vos::OGuard aSolarGuard( Application::GetSolarMutex());
252         createDialogOnDemand();
253         if( !m_pDialog )
254             return nRet;
255         TimerTriggeredControllerLock aTimerTriggeredControllerLock( m_xChartModel );
256         if( m_bUnlockControllersOnExecute && m_xChartModel.is() )
257             m_xChartModel->unlockControllers();
258         nRet = m_pDialog->Execute();
259     }
260     return nRet;
261 }
262 
263 //-------------------------------------------------------------------------
initialize(const uno::Sequence<uno::Any> & aArguments)264 void SAL_CALL CreationWizardUnoDlg::initialize( const uno::Sequence< uno::Any >& aArguments )
265 {
266     const uno::Any* pArguments = aArguments.getConstArray();
267     for(sal_Int32 i=0; i<aArguments.getLength(); ++i, ++pArguments)
268     {
269         beans::PropertyValue aProperty;
270         if(*pArguments >>= aProperty)
271         {
272             if( aProperty.Name.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "ParentWindow" ) ) == 0 )
273             {
274                 aProperty.Value >>= m_xParentWindow;
275             }
276             else if( aProperty.Name.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "ChartModel" ) ) == 0 )
277             {
278                 aProperty.Value >>= m_xChartModel;
279             }
280         }
281     }
282 }
283 
284 //-------------------------------------------------------------------------
285 // ____ OComponentHelper ____
286 /// Called in dispose method after the listeners were notified.
disposing()287 void SAL_CALL CreationWizardUnoDlg::disposing()
288 {
289     m_xChartModel.clear();
290     m_xParentWindow.clear();
291 
292     // /--
293     ::vos::OGuard aSolarGuard( Application::GetSolarMutex());
294     if( m_pDialog )
295     {
296         delete m_pDialog;
297         m_pDialog = 0;
298     }
299 
300     try
301     {
302         uno::Reference< frame::XDesktop > xDesktop(
303             m_xCC->getServiceManager()->createInstanceWithContext(
304                 C2U( "com.sun.star.frame.Desktop" ), m_xCC ), uno::UNO_QUERY );
305         if( xDesktop.is() )
306         {
307             uno::Reference< frame::XTerminateListener > xListener( this );
308             xDesktop->removeTerminateListener( xListener );
309         }
310     }
311     catch( const uno::Exception & ex )
312     {
313         ASSERT_EXCEPTION( ex );
314     }
315     // \--
316 }
317 
318 //XPropertySet
getPropertySetInfo()319 uno::Reference< beans::XPropertySetInfo > SAL_CALL CreationWizardUnoDlg::getPropertySetInfo()
320 {
321     OSL_ENSURE(false,"not implemented");
322     return 0;
323 }
324 
setPropertyValue(const::rtl::OUString & rPropertyName,const uno::Any & rValue)325 void SAL_CALL CreationWizardUnoDlg::setPropertyValue( const ::rtl::OUString& rPropertyName
326                                                      , const uno::Any& rValue )
327 {
328     if( rPropertyName.equals(C2U("Position")) )
329     {
330         awt::Point aPos;
331         if( ! (rValue >>= aPos) )
332             throw lang::IllegalArgumentException( C2U("Property 'Position' requires value of type awt::Point"), 0, 0 );
333 
334         //set left upper outer corner relative to screen
335         //pixels, screen position
336         ::vos::OGuard aSolarGuard( Application::GetSolarMutex());
337         createDialogOnDemand();
338         if( m_pDialog )
339         {
340             m_pDialog->SetPosPixel( Point(0,0) );
341             Rectangle aRect( m_pDialog->GetWindowExtentsRelative( 0 ) );
342 
343             Point aNewOuterPos = Point( aPos.X - aRect.Left(), aPos.Y - aRect.Top() );
344             m_pDialog->SetPosPixel( aNewOuterPos );
345         }
346     }
347     else if( rPropertyName.equals(C2U("Size")) )
348     {
349         //read only property, do nothing
350     }
351     else if( rPropertyName.equals(C2U("UnlockControllersOnExecute")) )
352     {
353         if( ! (rValue >>= m_bUnlockControllersOnExecute) )
354             throw lang::IllegalArgumentException( C2U("Property 'UnlockControllers' requires value of type boolean"), 0, 0 );
355     }
356     else
357         throw beans::UnknownPropertyException( C2U("unknown property was tried to set to chart wizard"), 0 );
358 }
359 
getPropertyValue(const::rtl::OUString & rPropertyName)360 uno::Any SAL_CALL CreationWizardUnoDlg::getPropertyValue( const ::rtl::OUString& rPropertyName )
361 {
362     uno::Any aRet;
363     if( rPropertyName.equals(C2U("Position")) )
364     {
365         //get left upper outer corner relative to screen
366         //pixels, screen position
367         ::vos::OGuard aSolarGuard( Application::GetSolarMutex());
368         createDialogOnDemand();
369         if( m_pDialog )
370         {
371             Rectangle aRect( m_pDialog->GetWindowExtentsRelative( 0 ) );
372             awt::Point aPoint(aRect.Left(),aRect.Top());
373             aRet = uno::makeAny( aPoint );
374         }
375     }
376     else if( rPropertyName.equals(C2U("Size")) )
377     {
378         //get outer size inclusive decoration
379         //pixels, screen position
380         ::vos::OGuard aSolarGuard( Application::GetSolarMutex());
381         createDialogOnDemand();
382         if( m_pDialog )
383         {
384             Rectangle aRect( m_pDialog->GetWindowExtentsRelative( 0 ) );
385             awt::Size aSize(aRect.GetWidth(),aRect.GetHeight());
386             aRet = uno::makeAny( aSize );
387         }
388     }
389     else if( rPropertyName.equals(C2U("UnlockControllersOnExecute")) )
390     {
391         aRet = uno::makeAny( m_bUnlockControllersOnExecute );
392     }
393     else
394         throw beans::UnknownPropertyException( C2U("unknown property was tried to get from chart wizard"), 0 );
395     return aRet;
396 }
397 
addPropertyChangeListener(const::rtl::OUString &,const uno::Reference<beans::XPropertyChangeListener> &)398 void SAL_CALL CreationWizardUnoDlg::addPropertyChangeListener(
399         const ::rtl::OUString& /* aPropertyName */, const uno::Reference< beans::XPropertyChangeListener >& /* xListener */ )
400 {
401     OSL_ENSURE(false,"not implemented");
402 }
removePropertyChangeListener(const::rtl::OUString &,const uno::Reference<beans::XPropertyChangeListener> &)403 void SAL_CALL CreationWizardUnoDlg::removePropertyChangeListener(
404     const ::rtl::OUString& /* aPropertyName */, const uno::Reference< beans::XPropertyChangeListener >& /* aListener */ )
405 {
406     OSL_ENSURE(false,"not implemented");
407 }
408 
addVetoableChangeListener(const::rtl::OUString &,const uno::Reference<beans::XVetoableChangeListener> &)409 void SAL_CALL CreationWizardUnoDlg::addVetoableChangeListener( const ::rtl::OUString& /* PropertyName */, const uno::Reference< beans::XVetoableChangeListener >& /* aListener */ )
410 {
411     OSL_ENSURE(false,"not implemented");
412 }
413 
removeVetoableChangeListener(const::rtl::OUString &,const uno::Reference<beans::XVetoableChangeListener> &)414 void SAL_CALL CreationWizardUnoDlg::removeVetoableChangeListener( const ::rtl::OUString& /* PropertyName */, const uno::Reference< beans::XVetoableChangeListener >& /* aListener */ )
415 {
416     OSL_ENSURE(false,"not implemented");
417 }
418 
419 //.............................................................................
420 } //namespace chart
421 //.............................................................................
422