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_extensions.hxx"
30*cdf0e10cSrcweir #include "sqlcommanddesign.hxx"
31*cdf0e10cSrcweir #include "formstrings.hxx"
32*cdf0e10cSrcweir #ifndef _EXTENSIONS_FORMCTRLR_PROPRESID_HRC_
33*cdf0e10cSrcweir #include "formresid.hrc"
34*cdf0e10cSrcweir #endif
35*cdf0e10cSrcweir #ifndef _EXTENSIONS_PROPCTRLR_MODULEPRC_HXX_
36*cdf0e10cSrcweir #include "modulepcr.hxx"
37*cdf0e10cSrcweir #endif
38*cdf0e10cSrcweir #include "unourl.hxx"
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir /** === begin UNO includes === **/
41*cdf0e10cSrcweir #include <com/sun/star/awt/XWindow.hpp>
42*cdf0e10cSrcweir #include <com/sun/star/awt/XTopWindow.hpp>
43*cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
44*cdf0e10cSrcweir #include <com/sun/star/frame/XTitle.hpp>
45*cdf0e10cSrcweir #include <com/sun/star/frame/XComponentLoader.hpp>
46*cdf0e10cSrcweir #include <com/sun/star/frame/XController.hpp>
47*cdf0e10cSrcweir #include <com/sun/star/lang/NullPointerException.hpp>
48*cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
49*cdf0e10cSrcweir #include <com/sun/star/frame/FrameSearchFlag.hpp>
50*cdf0e10cSrcweir #include <com/sun/star/frame/XFramesSupplier.hpp>
51*cdf0e10cSrcweir #include <com/sun/star/sdbc/XConnection.hpp>
52*cdf0e10cSrcweir #include <com/sun/star/util/XCloseable.hpp>
53*cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProvider.hpp>
54*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySetInfo.hpp>
55*cdf0e10cSrcweir #include <com/sun/star/sdb/CommandType.hpp>
56*cdf0e10cSrcweir /** === end UNO includes === **/
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir #include <svtools/localresaccess.hxx>
59*cdf0e10cSrcweir #include <tools/diagnose_ex.h>
60*cdf0e10cSrcweir #include <osl/diagnose.h>
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir //........................................................................
63*cdf0e10cSrcweir namespace pcr
64*cdf0e10cSrcweir {
65*cdf0e10cSrcweir //........................................................................
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir     /** === begin UNO using === **/
68*cdf0e10cSrcweir     using ::com::sun::star::uno::Reference;
69*cdf0e10cSrcweir     using ::com::sun::star::lang::XMultiComponentFactory;
70*cdf0e10cSrcweir     using ::com::sun::star::beans::PropertyChangeEvent;
71*cdf0e10cSrcweir     using ::com::sun::star::uno::RuntimeException;
72*cdf0e10cSrcweir     using ::com::sun::star::frame::XFrame;
73*cdf0e10cSrcweir     using ::com::sun::star::awt::XTopWindow;
74*cdf0e10cSrcweir     using ::com::sun::star::awt::XWindow;
75*cdf0e10cSrcweir     using ::com::sun::star::uno::Exception;
76*cdf0e10cSrcweir     using ::com::sun::star::uno::UNO_QUERY_THROW;
77*cdf0e10cSrcweir     using ::com::sun::star::uno::UNO_QUERY;
78*cdf0e10cSrcweir     using ::com::sun::star::beans::PropertyValue;
79*cdf0e10cSrcweir     using ::com::sun::star::uno::Sequence;
80*cdf0e10cSrcweir     using ::com::sun::star::lang::XComponent;
81*cdf0e10cSrcweir     using ::com::sun::star::frame::XComponentLoader;
82*cdf0e10cSrcweir     using ::com::sun::star::beans::XPropertySet;
83*cdf0e10cSrcweir     using ::com::sun::star::beans::XPropertySetInfo;
84*cdf0e10cSrcweir     using ::com::sun::star::frame::XController;
85*cdf0e10cSrcweir     using ::com::sun::star::frame::XTitle;
86*cdf0e10cSrcweir     using ::com::sun::star::lang::EventObject;
87*cdf0e10cSrcweir     using ::com::sun::star::lang::NullPointerException;
88*cdf0e10cSrcweir     using ::com::sun::star::lang::DisposedException;
89*cdf0e10cSrcweir     using ::com::sun::star::uno::makeAny;
90*cdf0e10cSrcweir     using ::com::sun::star::uno::XComponentContext;
91*cdf0e10cSrcweir     using ::com::sun::star::frame::XFramesSupplier;
92*cdf0e10cSrcweir     using ::com::sun::star::frame::XFrames;
93*cdf0e10cSrcweir     using ::com::sun::star::util::XCloseable;
94*cdf0e10cSrcweir     using ::com::sun::star::uno::TypeClass_STRING;
95*cdf0e10cSrcweir     using ::com::sun::star::lang::XMultiServiceFactory;
96*cdf0e10cSrcweir     using ::com::sun::star::frame::XDispatchProvider;
97*cdf0e10cSrcweir     using ::com::sun::star::frame::XDispatch;
98*cdf0e10cSrcweir     using ::com::sun::star::uno::Any;
99*cdf0e10cSrcweir     /** === end UNO using === **/
100*cdf0e10cSrcweir     namespace FrameSearchFlag = ::com::sun::star::frame::FrameSearchFlag;
101*cdf0e10cSrcweir     namespace CommandType = ::com::sun::star::sdb::CommandType;
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir 	//====================================================================
104*cdf0e10cSrcweir 	//= ISQLCommandAdapter
105*cdf0e10cSrcweir 	//====================================================================
106*cdf0e10cSrcweir 	//--------------------------------------------------------------------
107*cdf0e10cSrcweir     ISQLCommandAdapter::~ISQLCommandAdapter()
108*cdf0e10cSrcweir     {
109*cdf0e10cSrcweir     }
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir     //====================================================================
112*cdf0e10cSrcweir 	//= SQLCommandDesigner
113*cdf0e10cSrcweir 	//====================================================================
114*cdf0e10cSrcweir 	//--------------------------------------------------------------------
115*cdf0e10cSrcweir     SQLCommandDesigner::SQLCommandDesigner( const Reference< XComponentContext >& _rxContext,
116*cdf0e10cSrcweir             const ::rtl::Reference< ISQLCommandAdapter >& _rxPropertyAdapter,
117*cdf0e10cSrcweir             const ::dbtools::SharedConnection& _rConnection, const Link& _rCloseLink )
118*cdf0e10cSrcweir         :m_xContext( _rxContext )
119*cdf0e10cSrcweir         ,m_xConnection( _rConnection )
120*cdf0e10cSrcweir         ,m_xObjectAdapter( _rxPropertyAdapter )
121*cdf0e10cSrcweir         ,m_aCloseLink( _rCloseLink )
122*cdf0e10cSrcweir     {
123*cdf0e10cSrcweir         if ( m_xContext.is() )
124*cdf0e10cSrcweir             m_xORB = m_xContext->getServiceManager();
125*cdf0e10cSrcweir         if ( !m_xORB.is() || !_rxPropertyAdapter.is() || !m_xConnection.is() )
126*cdf0e10cSrcweir             throw NullPointerException();
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir         impl_doOpenDesignerFrame_nothrow();
129*cdf0e10cSrcweir     }
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir 	//--------------------------------------------------------------------
132*cdf0e10cSrcweir     SQLCommandDesigner::~SQLCommandDesigner()
133*cdf0e10cSrcweir     {
134*cdf0e10cSrcweir     }
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir     //--------------------------------------------------------------------
137*cdf0e10cSrcweir     void SAL_CALL SQLCommandDesigner::propertyChange( const PropertyChangeEvent& Event ) throw (RuntimeException)
138*cdf0e10cSrcweir     {
139*cdf0e10cSrcweir         OSL_ENSURE( m_xDesigner.is() && ( Event.Source == m_xDesigner ), "SQLCommandDesigner::propertyChange: where did this come from?" );
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir         if ( m_xDesigner.is() && ( Event.Source == m_xDesigner ) )
142*cdf0e10cSrcweir         {
143*cdf0e10cSrcweir             try
144*cdf0e10cSrcweir             {
145*cdf0e10cSrcweir                 if ( PROPERTY_ACTIVECOMMAND == Event.PropertyName )
146*cdf0e10cSrcweir                 {
147*cdf0e10cSrcweir                     ::rtl::OUString sCommand;
148*cdf0e10cSrcweir                     OSL_VERIFY( Event.NewValue >>= sCommand );
149*cdf0e10cSrcweir                     m_xObjectAdapter->setSQLCommand( sCommand );
150*cdf0e10cSrcweir                 }
151*cdf0e10cSrcweir                 else if ( PROPERTY_ESCAPE_PROCESSING == Event.PropertyName )
152*cdf0e10cSrcweir                 {
153*cdf0e10cSrcweir                     sal_Bool bEscapeProcessing( sal_False );
154*cdf0e10cSrcweir                     OSL_VERIFY( Event.NewValue >>= bEscapeProcessing );
155*cdf0e10cSrcweir                     m_xObjectAdapter->setEscapeProcessing( bEscapeProcessing );
156*cdf0e10cSrcweir                 }
157*cdf0e10cSrcweir             }
158*cdf0e10cSrcweir             catch( const RuntimeException& ) { throw; }
159*cdf0e10cSrcweir             catch( const Exception& )
160*cdf0e10cSrcweir             {
161*cdf0e10cSrcweir                 // not allowed to leave, so silence it
162*cdf0e10cSrcweir                 DBG_UNHANDLED_EXCEPTION();
163*cdf0e10cSrcweir             }
164*cdf0e10cSrcweir         }
165*cdf0e10cSrcweir     }
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir     //--------------------------------------------------------------------
168*cdf0e10cSrcweir     void SAL_CALL SQLCommandDesigner::disposing( const EventObject& Source ) throw (RuntimeException)
169*cdf0e10cSrcweir     {
170*cdf0e10cSrcweir         if ( m_xDesigner.is() && ( Source.Source == m_xDesigner ) )
171*cdf0e10cSrcweir         {
172*cdf0e10cSrcweir             impl_designerClosed_nothrow();
173*cdf0e10cSrcweir             m_xDesigner.clear();
174*cdf0e10cSrcweir         }
175*cdf0e10cSrcweir     }
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir     //--------------------------------------------------------------------
178*cdf0e10cSrcweir     void SQLCommandDesigner::dispose()
179*cdf0e10cSrcweir     {
180*cdf0e10cSrcweir         if ( impl_isDisposed() )
181*cdf0e10cSrcweir             return;
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir         if ( isActive() )
184*cdf0e10cSrcweir             impl_closeDesigner_nothrow();
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir         m_xConnection.clear();
187*cdf0e10cSrcweir         m_xContext.clear();
188*cdf0e10cSrcweir         m_xORB.clear();
189*cdf0e10cSrcweir     }
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir     //--------------------------------------------------------------------
192*cdf0e10cSrcweir     void SQLCommandDesigner::impl_checkDisposed_throw() const
193*cdf0e10cSrcweir     {
194*cdf0e10cSrcweir         if ( impl_isDisposed() )
195*cdf0e10cSrcweir             throw DisposedException();
196*cdf0e10cSrcweir     }
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir     //--------------------------------------------------------------------
199*cdf0e10cSrcweir     void SQLCommandDesigner::raise() const
200*cdf0e10cSrcweir     {
201*cdf0e10cSrcweir         impl_checkDisposed_throw();
202*cdf0e10cSrcweir         impl_raise_nothrow();
203*cdf0e10cSrcweir     }
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir 	//------------------------------------------------------------------------
206*cdf0e10cSrcweir     bool SQLCommandDesigner::suspend() const
207*cdf0e10cSrcweir     {
208*cdf0e10cSrcweir         impl_checkDisposed_throw();
209*cdf0e10cSrcweir         return impl_trySuspendDesigner_nothrow();
210*cdf0e10cSrcweir     }
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir     //--------------------------------------------------------------------
213*cdf0e10cSrcweir     void SQLCommandDesigner::impl_raise_nothrow() const
214*cdf0e10cSrcweir     {
215*cdf0e10cSrcweir         OSL_PRECOND( isActive(), "SQLCommandDesigner::impl_raise_nothrow: not active!" );
216*cdf0e10cSrcweir         if ( !isActive() )
217*cdf0e10cSrcweir             return;
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir         try
220*cdf0e10cSrcweir         {
221*cdf0e10cSrcweir             // activate the frame for this component
222*cdf0e10cSrcweir             Reference< XFrame >     xFrame( m_xDesigner->getFrame(), UNO_QUERY_THROW );
223*cdf0e10cSrcweir             Reference< XWindow >    xWindow( xFrame->getContainerWindow(), UNO_QUERY_THROW );
224*cdf0e10cSrcweir             Reference< XTopWindow > xTopWindow( xWindow, UNO_QUERY_THROW );
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir             xTopWindow->toFront();
227*cdf0e10cSrcweir             xWindow->setFocus();
228*cdf0e10cSrcweir         }
229*cdf0e10cSrcweir         catch( const Exception& )
230*cdf0e10cSrcweir         {
231*cdf0e10cSrcweir             DBG_UNHANDLED_EXCEPTION();
232*cdf0e10cSrcweir         }
233*cdf0e10cSrcweir     }
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir     //--------------------------------------------------------------------
236*cdf0e10cSrcweir     void SQLCommandDesigner::impl_doOpenDesignerFrame_nothrow()
237*cdf0e10cSrcweir     {
238*cdf0e10cSrcweir         OSL_PRECOND( !isActive(),
239*cdf0e10cSrcweir             "SQLCommandDesigner::impl_doOpenDesignerFrame_nothrow: already active!" );
240*cdf0e10cSrcweir         OSL_PRECOND( m_xConnection.is(), "SQLCommandDesigner::impl_doOpenDesignerFrame_nothrow: this will crash!" );
241*cdf0e10cSrcweir         osl_incrementInterlockedCount(&m_refCount);
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir         try
244*cdf0e10cSrcweir         {
245*cdf0e10cSrcweir             // for various reasons, we don't want the new frame to appear in the desktop's frame list
246*cdf0e10cSrcweir             // thus, we create a blank frame at the desktop, remove it from the desktop's frame list
247*cdf0e10cSrcweir             // immediately, and then load the component into this blank (and now parent-less) frame
248*cdf0e10cSrcweir 			Reference< XComponentLoader > xLoader( impl_createEmptyParentlessTask_nothrow(), UNO_QUERY_THROW );
249*cdf0e10cSrcweir             Sequence< PropertyValue > aArgs( 5 );
250*cdf0e10cSrcweir             aArgs[0].Name = PROPERTY_ACTIVE_CONNECTION;
251*cdf0e10cSrcweir             aArgs[0].Value <<= m_xConnection.getTyped();
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir             aArgs[1].Name  = PROPERTY_COMMAND;
254*cdf0e10cSrcweir             aArgs[1].Value <<= m_xObjectAdapter->getSQLCommand();
255*cdf0e10cSrcweir             aArgs[2].Name  = PROPERTY_COMMANDTYPE;
256*cdf0e10cSrcweir             aArgs[2].Value <<= (sal_Int32)CommandType::COMMAND;
257*cdf0e10cSrcweir             aArgs[3].Name  = PROPERTY_ESCAPE_PROCESSING;
258*cdf0e10cSrcweir             aArgs[3].Value <<= m_xObjectAdapter->getEscapeProcessing();
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir             aArgs[4].Name  = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "GraphicalDesign" ) );
261*cdf0e10cSrcweir             aArgs[4].Value <<= m_xObjectAdapter->getEscapeProcessing();
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir 			Reference< XComponent > xQueryDesign = xLoader->loadComponentFromURL(
264*cdf0e10cSrcweir                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".component:DB/QueryDesign" ) ),
265*cdf0e10cSrcweir 				::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_self" ) ),
266*cdf0e10cSrcweir 				FrameSearchFlag::TASKS | FrameSearchFlag::CREATE,
267*cdf0e10cSrcweir 				aArgs
268*cdf0e10cSrcweir 			);
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir             // remember this newly loaded component - we need to care for it e.g. when we're suspended
271*cdf0e10cSrcweir             m_xDesigner = m_xDesigner.query( xQueryDesign );
272*cdf0e10cSrcweir             OSL_ENSURE( m_xDesigner.is() || !xQueryDesign.is(), "SQLCommandDesigner::impl_doOpenDesignerFrame_nothrow: the component is expected to be a controller!" );
273*cdf0e10cSrcweir             if ( m_xDesigner.is() )
274*cdf0e10cSrcweir             {
275*cdf0e10cSrcweir                 Reference< XPropertySet > xQueryDesignProps( m_xDesigner, UNO_QUERY );
276*cdf0e10cSrcweir                 OSL_ENSURE( xQueryDesignProps.is(), "SQLCommandDesigner::impl_doOpenDesignerFrame_nothrow: the controller should have properties!" );
277*cdf0e10cSrcweir                 if ( xQueryDesignProps.is() )
278*cdf0e10cSrcweir                 {
279*cdf0e10cSrcweir                     xQueryDesignProps->addPropertyChangeListener( PROPERTY_ACTIVECOMMAND, this );
280*cdf0e10cSrcweir                     xQueryDesignProps->addPropertyChangeListener( PROPERTY_ESCAPE_PROCESSING, this );
281*cdf0e10cSrcweir                 }
282*cdf0e10cSrcweir             }
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir             // get the frame which we just opened and set it's title
285*cdf0e10cSrcweir             Reference< XTitle> xTitle(xQueryDesign,UNO_QUERY);
286*cdf0e10cSrcweir             if ( xTitle.is() )
287*cdf0e10cSrcweir             {
288*cdf0e10cSrcweir                 ::svt::OLocalResourceAccess aEnumStrings( PcrRes( RID_RSC_ENUM_COMMAND_TYPE ), RSC_RESOURCE );
289*cdf0e10cSrcweir 	            ::rtl::OUString sDisplayName = String( PcrRes( CommandType::COMMAND + 1 ) );
290*cdf0e10cSrcweir     	        xTitle->setTitle( sDisplayName );
291*cdf0e10cSrcweir             }
292*cdf0e10cSrcweir         }
293*cdf0e10cSrcweir         catch( const Exception& )
294*cdf0e10cSrcweir         {
295*cdf0e10cSrcweir             DBG_UNHANDLED_EXCEPTION();
296*cdf0e10cSrcweir             m_xDesigner.clear();
297*cdf0e10cSrcweir         }
298*cdf0e10cSrcweir         osl_decrementInterlockedCount(&m_refCount);
299*cdf0e10cSrcweir     }
300*cdf0e10cSrcweir 
301*cdf0e10cSrcweir 	//------------------------------------------------------------------------
302*cdf0e10cSrcweir     Reference< XFrame > SQLCommandDesigner::impl_createEmptyParentlessTask_nothrow( ) const
303*cdf0e10cSrcweir     {
304*cdf0e10cSrcweir         OSL_PRECOND( m_xORB.is(), "SQLCommandDesigner::impl_createEmptyParentlessTask_nothrow: this will crash!" );
305*cdf0e10cSrcweir 
306*cdf0e10cSrcweir         Reference< XFrame > xFrame;
307*cdf0e10cSrcweir         try
308*cdf0e10cSrcweir         {
309*cdf0e10cSrcweir             Reference< XInterface      > xDesktop          ( m_xORB->createInstanceWithContext( SERVICE_DESKTOP, m_xContext ) );
310*cdf0e10cSrcweir             Reference< XFrame          > xDesktopFrame     ( xDesktop,      UNO_QUERY_THROW );
311*cdf0e10cSrcweir             Reference< XFramesSupplier > xSuppDesktopFrames( xDesktopFrame, UNO_QUERY_THROW );
312*cdf0e10cSrcweir 
313*cdf0e10cSrcweir             Reference< XFrames > xDesktopFramesCollection( xSuppDesktopFrames->getFrames(), UNO_QUERY_THROW );
314*cdf0e10cSrcweir             xFrame = xDesktopFrame->findFrame( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_blank" ) ), FrameSearchFlag::CREATE );
315*cdf0e10cSrcweir             OSL_ENSURE( xFrame.is(), "SQLCommandDesigner::impl_createEmptyParentlessTask_nothrow: could not create an empty frame!" );
316*cdf0e10cSrcweir             xDesktopFramesCollection->remove( xFrame );
317*cdf0e10cSrcweir         }
318*cdf0e10cSrcweir         catch( const Exception& )
319*cdf0e10cSrcweir         {
320*cdf0e10cSrcweir             DBG_UNHANDLED_EXCEPTION();
321*cdf0e10cSrcweir         }
322*cdf0e10cSrcweir         return xFrame;
323*cdf0e10cSrcweir     }
324*cdf0e10cSrcweir 
325*cdf0e10cSrcweir 	//------------------------------------------------------------------------
326*cdf0e10cSrcweir     void SQLCommandDesigner::impl_designerClosed_nothrow()
327*cdf0e10cSrcweir     {
328*cdf0e10cSrcweir         if ( m_aCloseLink.IsSet() )
329*cdf0e10cSrcweir             m_aCloseLink.Call( this );
330*cdf0e10cSrcweir     }
331*cdf0e10cSrcweir 
332*cdf0e10cSrcweir 	//------------------------------------------------------------------------
333*cdf0e10cSrcweir     void SQLCommandDesigner::impl_closeDesigner_nothrow()
334*cdf0e10cSrcweir     {
335*cdf0e10cSrcweir         OSL_PRECOND( isActive(), "SQLCommandDesigner::impl_closeDesigner_nothrow: invalid calle!" );
336*cdf0e10cSrcweir         // close it
337*cdf0e10cSrcweir         try
338*cdf0e10cSrcweir         {
339*cdf0e10cSrcweir             // do not listen anymore ....
340*cdf0e10cSrcweir             Reference< XPropertySet > xProps( m_xDesigner, UNO_QUERY );
341*cdf0e10cSrcweir             if ( xProps.is() )
342*cdf0e10cSrcweir                 xProps->removePropertyChangeListener( PROPERTY_ACTIVECOMMAND, this );
343*cdf0e10cSrcweir 
344*cdf0e10cSrcweir             // we need to close the frame via the "user interface", by dispatching a close command,
345*cdf0e10cSrcweir             // instead of calling XCloseable::close directly. The latter method would also close
346*cdf0e10cSrcweir             // the frame, but not care for things like shutting down the office when the last
347*cdf0e10cSrcweir             // frame is gone ...
348*cdf0e10cSrcweir             const UnoURL aCloseURL( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:CloseDoc" ) ),
349*cdf0e10cSrcweir                 Reference< XMultiServiceFactory >( m_xORB, UNO_QUERY ) );
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir             Reference< XDispatchProvider > xProvider( m_xDesigner->getFrame(), UNO_QUERY_THROW );
352*cdf0e10cSrcweir             Reference< XDispatch > xDispatch( xProvider->queryDispatch( aCloseURL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_top" ) ), FrameSearchFlag::SELF ) );
353*cdf0e10cSrcweir             OSL_ENSURE( xDispatch.is(), "SQLCommandDesigner::impl_closeDesigner_nothrow: no dispatcher for the CloseDoc command!" );
354*cdf0e10cSrcweir             if ( xDispatch.is() )
355*cdf0e10cSrcweir             {
356*cdf0e10cSrcweir                 xDispatch->dispatch( aCloseURL, Sequence< PropertyValue >( ) );
357*cdf0e10cSrcweir             }
358*cdf0e10cSrcweir             else
359*cdf0e10cSrcweir             {
360*cdf0e10cSrcweir                 // fallback: use the XCloseable::close (with all possible disadvantages)
361*cdf0e10cSrcweir                 Reference< XCloseable > xClose( m_xDesigner->getFrame(), UNO_QUERY );
362*cdf0e10cSrcweir                 if ( xClose.is() )
363*cdf0e10cSrcweir                     xClose->close( sal_True );
364*cdf0e10cSrcweir             }
365*cdf0e10cSrcweir         }
366*cdf0e10cSrcweir         catch( const Exception& )
367*cdf0e10cSrcweir         {
368*cdf0e10cSrcweir             DBG_UNHANDLED_EXCEPTION();
369*cdf0e10cSrcweir         }
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir         m_xDesigner.clear();
372*cdf0e10cSrcweir     }
373*cdf0e10cSrcweir 
374*cdf0e10cSrcweir 	//------------------------------------------------------------------------
375*cdf0e10cSrcweir     bool SQLCommandDesigner::impl_trySuspendDesigner_nothrow() const
376*cdf0e10cSrcweir     {
377*cdf0e10cSrcweir         OSL_PRECOND( isActive(), "SQLCommandDesigner::impl_trySuspendDesigner_nothrow: no active designer, this will crash!" );
378*cdf0e10cSrcweir         sal_Bool bAllow = sal_True;
379*cdf0e10cSrcweir         try
380*cdf0e10cSrcweir         {
381*cdf0e10cSrcweir             bAllow = m_xDesigner->suspend( sal_True );
382*cdf0e10cSrcweir         }
383*cdf0e10cSrcweir         catch( const Exception& )
384*cdf0e10cSrcweir         {
385*cdf0e10cSrcweir             DBG_UNHANDLED_EXCEPTION();
386*cdf0e10cSrcweir         }
387*cdf0e10cSrcweir         return bAllow;
388*cdf0e10cSrcweir     }
389*cdf0e10cSrcweir 
390*cdf0e10cSrcweir //........................................................................
391*cdf0e10cSrcweir } // namespace pcr
392*cdf0e10cSrcweir //........................................................................
393*cdf0e10cSrcweir 
394