2010-10-12 15:57:08 +02:00
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2012-06-21 14:30:25 +01:00
/*
* This file is part of the LibreOffice project .
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License , v . 2.0 . If a copy of the MPL was not distributed with this
* file , You can obtain one at http : //mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice :
*
* Licensed to the Apache Software Foundation ( ASF ) under one or more
* contributor license agreements . See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership . The ASF licenses this file to you under the Apache
* License , Version 2.0 ( the " License " ) ; you may not use this file
* except in compliance with the License . You may obtain a copy of
* the License at http : //www.apache.org/licenses/LICENSE-2.0 .
*/
2006-03-14 10:32:32 +00:00
# include "sqlcommanddesign.hxx"
# include "formstrings.hxx"
2017-10-23 22:41:56 +02:00
# include <command.hrc>
# include <strings.hrc>
2006-03-14 10:32:32 +00:00
# include "modulepcr.hxx"
# include "unourl.hxx"
# include <com/sun/star/awt/XWindow.hpp>
# include <com/sun/star/awt/XTopWindow.hpp>
# include <com/sun/star/uno/Sequence.hxx>
2012-12-14 12:58:00 +02:00
# include <com/sun/star/frame/Desktop.hpp>
2008-04-04 13:06:33 +00:00
# include <com/sun/star/frame/XTitle.hpp>
2006-03-14 10:32:32 +00:00
# include <com/sun/star/frame/XComponentLoader.hpp>
# include <com/sun/star/lang/NullPointerException.hpp>
# include <com/sun/star/lang/DisposedException.hpp>
# include <com/sun/star/frame/FrameSearchFlag.hpp>
# include <com/sun/star/sdbc/XConnection.hpp>
# include <com/sun/star/util/XCloseable.hpp>
# include <com/sun/star/frame/XDispatchProvider.hpp>
2007-05-10 09:49:49 +00:00
# include <com/sun/star/sdb/CommandType.hpp>
2006-03-14 10:32:32 +00:00
2007-05-10 09:49:49 +00:00
# include <tools/diagnose_ex.h>
# include <osl/diagnose.h>
2006-03-14 10:32:32 +00:00
2014-02-25 18:36:00 +01:00
2006-03-14 10:32:32 +00:00
namespace pcr
{
2014-02-25 18:36:00 +01:00
2006-03-14 10:32:32 +00:00
using : : com : : sun : : star : : uno : : Reference ;
using : : com : : sun : : star : : beans : : PropertyChangeEvent ;
using : : com : : sun : : star : : uno : : RuntimeException ;
using : : com : : sun : : star : : frame : : XFrame ;
using : : com : : sun : : star : : awt : : XTopWindow ;
using : : com : : sun : : star : : awt : : XWindow ;
using : : com : : sun : : star : : uno : : Exception ;
using : : com : : sun : : star : : uno : : UNO_QUERY_THROW ;
using : : com : : sun : : star : : uno : : UNO_QUERY ;
using : : com : : sun : : star : : beans : : PropertyValue ;
using : : com : : sun : : star : : uno : : Sequence ;
using : : com : : sun : : star : : lang : : XComponent ;
using : : com : : sun : : star : : frame : : XComponentLoader ;
using : : com : : sun : : star : : beans : : XPropertySet ;
2008-04-04 13:06:33 +00:00
using : : com : : sun : : star : : frame : : XTitle ;
2006-03-14 10:32:32 +00:00
using : : com : : sun : : star : : lang : : EventObject ;
using : : com : : sun : : star : : lang : : NullPointerException ;
using : : com : : sun : : star : : lang : : DisposedException ;
using : : com : : sun : : star : : uno : : XComponentContext ;
using : : com : : sun : : star : : frame : : XFrames ;
using : : com : : sun : : star : : util : : XCloseable ;
using : : com : : sun : : star : : lang : : XMultiServiceFactory ;
using : : com : : sun : : star : : frame : : XDispatchProvider ;
using : : com : : sun : : star : : frame : : XDispatch ;
2012-12-14 12:58:00 +02:00
using : : com : : sun : : star : : frame : : Desktop ;
using : : com : : sun : : star : : frame : : XDesktop2 ;
2013-04-01 18:45:57 +02:00
2007-05-10 09:49:49 +00:00
namespace FrameSearchFlag = : : com : : sun : : star : : frame : : FrameSearchFlag ;
namespace CommandType = : : com : : sun : : star : : sdb : : CommandType ;
2006-03-14 10:32:32 +00:00
2014-02-25 18:36:00 +01:00
2007-11-21 15:22:32 +00:00
//= ISQLCommandAdapter
2014-02-25 18:36:00 +01:00
2014-02-22 21:20:15 +01:00
2007-11-21 15:22:32 +00:00
ISQLCommandAdapter : : ~ ISQLCommandAdapter ( )
{
}
2014-02-25 18:36:00 +01:00
2006-03-14 10:32:32 +00:00
//= SQLCommandDesigner
2014-02-25 18:36:00 +01:00
2014-02-22 21:20:15 +01:00
2006-03-14 10:32:32 +00:00
SQLCommandDesigner : : SQLCommandDesigner ( const Reference < XComponentContext > & _rxContext ,
2007-11-21 15:22:32 +00:00
const : : rtl : : Reference < ISQLCommandAdapter > & _rxPropertyAdapter ,
2015-09-17 09:22:25 +02:00
const : : dbtools : : SharedConnection & _rConnection , const Link < SQLCommandDesigner & , void > & _rCloseLink )
2006-03-14 10:32:32 +00:00
: m_xContext ( _rxContext )
, m_xConnection ( _rConnection )
2007-11-21 15:22:32 +00:00
, m_xObjectAdapter ( _rxPropertyAdapter )
2006-03-14 10:32:32 +00:00
, m_aCloseLink ( _rCloseLink )
{
if ( m_xContext . is ( ) )
m_xORB = m_xContext - > getServiceManager ( ) ;
2007-11-21 15:22:32 +00:00
if ( ! m_xORB . is ( ) | | ! _rxPropertyAdapter . is ( ) | | ! m_xConnection . is ( ) )
2006-03-14 10:32:32 +00:00
throw NullPointerException ( ) ;
impl_doOpenDesignerFrame_nothrow ( ) ;
}
2014-02-22 21:20:15 +01:00
2006-03-14 10:32:32 +00:00
SQLCommandDesigner : : ~ SQLCommandDesigner ( )
{
}
2014-02-22 21:20:15 +01:00
2017-01-26 12:28:58 +01:00
void SAL_CALL SQLCommandDesigner : : propertyChange ( const PropertyChangeEvent & Event )
2006-03-14 10:32:32 +00:00
{
OSL_ENSURE ( m_xDesigner . is ( ) & & ( Event . Source = = m_xDesigner ) , " SQLCommandDesigner::propertyChange: where did this come from? " ) ;
if ( m_xDesigner . is ( ) & & ( Event . Source = = m_xDesigner ) )
{
2007-11-21 15:22:32 +00:00
try
2006-03-14 10:32:32 +00:00
{
2007-11-21 15:22:32 +00:00
if ( PROPERTY_ACTIVECOMMAND = = Event . PropertyName )
2007-05-10 09:49:49 +00:00
{
2013-04-07 12:06:47 +02:00
OUString sCommand ;
2007-11-21 15:22:32 +00:00
OSL_VERIFY ( Event . NewValue > > = sCommand ) ;
m_xObjectAdapter - > setSQLCommand ( sCommand ) ;
2007-05-10 09:49:49 +00:00
}
2007-11-21 15:22:32 +00:00
else if ( PROPERTY_ESCAPE_PROCESSING = = Event . PropertyName )
2007-05-10 09:49:49 +00:00
{
2014-04-30 11:46:15 +02:00
bool bEscapeProcessing ( false ) ;
2007-11-21 15:22:32 +00:00
OSL_VERIFY ( Event . NewValue > > = bEscapeProcessing ) ;
m_xObjectAdapter - > setEscapeProcessing ( bEscapeProcessing ) ;
2007-05-10 09:49:49 +00:00
}
2006-03-14 10:32:32 +00:00
}
2007-11-21 15:22:32 +00:00
catch ( const RuntimeException & ) { throw ; }
catch ( const Exception & )
{
// not allowed to leave, so silence it
DBG_UNHANDLED_EXCEPTION ( ) ;
}
2006-03-14 10:32:32 +00:00
}
}
2014-02-22 21:20:15 +01:00
2017-01-26 12:28:58 +01:00
void SAL_CALL SQLCommandDesigner : : disposing ( const EventObject & Source )
2006-03-14 10:32:32 +00:00
{
if ( m_xDesigner . is ( ) & & ( Source . Source = = m_xDesigner ) )
{
2016-11-08 11:10:50 +02:00
m_aCloseLink . Call ( * this ) ;
2006-03-14 10:32:32 +00:00
m_xDesigner . clear ( ) ;
}
}
2014-02-22 21:20:15 +01:00
2006-03-14 10:32:32 +00:00
void SQLCommandDesigner : : dispose ( )
{
if ( impl_isDisposed ( ) )
return ;
if ( isActive ( ) )
2007-05-10 09:49:49 +00:00
impl_closeDesigner_nothrow ( ) ;
2006-03-14 10:32:32 +00:00
m_xConnection . clear ( ) ;
m_xContext . clear ( ) ;
m_xORB . clear ( ) ;
}
2014-02-22 21:20:15 +01:00
2006-03-14 10:32:32 +00:00
void SQLCommandDesigner : : impl_checkDisposed_throw ( ) const
{
if ( impl_isDisposed ( ) )
throw DisposedException ( ) ;
}
2014-02-22 21:20:15 +01:00
2006-03-14 10:32:32 +00:00
void SQLCommandDesigner : : raise ( ) const
{
impl_checkDisposed_throw ( ) ;
impl_raise_nothrow ( ) ;
}
2014-02-22 21:20:15 +01:00
2006-03-14 10:32:32 +00:00
bool SQLCommandDesigner : : suspend ( ) const
{
impl_checkDisposed_throw ( ) ;
return impl_trySuspendDesigner_nothrow ( ) ;
}
2014-02-22 21:20:15 +01:00
2006-03-14 10:32:32 +00:00
void SQLCommandDesigner : : impl_raise_nothrow ( ) const
{
OSL_PRECOND ( isActive ( ) , " SQLCommandDesigner::impl_raise_nothrow: not active! " ) ;
if ( ! isActive ( ) )
return ;
try
{
// activate the frame for this component
Reference < XFrame > xFrame ( m_xDesigner - > getFrame ( ) , UNO_QUERY_THROW ) ;
Reference < XWindow > xWindow ( xFrame - > getContainerWindow ( ) , UNO_QUERY_THROW ) ;
Reference < XTopWindow > xTopWindow ( xWindow , UNO_QUERY_THROW ) ;
xTopWindow - > toFront ( ) ;
xWindow - > setFocus ( ) ;
}
catch ( const Exception & )
{
2007-05-10 09:49:49 +00:00
DBG_UNHANDLED_EXCEPTION ( ) ;
2006-03-14 10:32:32 +00:00
}
}
2014-02-22 21:20:15 +01:00
2006-03-14 10:32:32 +00:00
void SQLCommandDesigner : : impl_doOpenDesignerFrame_nothrow ( )
{
OSL_PRECOND ( ! isActive ( ) ,
" SQLCommandDesigner::impl_doOpenDesignerFrame_nothrow: already active! " ) ;
2007-11-21 15:22:32 +00:00
OSL_PRECOND ( m_xConnection . is ( ) , " SQLCommandDesigner::impl_doOpenDesignerFrame_nothrow: this will crash! " ) ;
2012-09-22 01:51:12 -05:00
osl_atomic_increment ( & m_refCount ) ;
2006-03-14 10:32:32 +00:00
try
{
// for various reasons, we don't want the new frame to appear in the desktop's frame list
// thus, we create a blank frame at the desktop, remove it from the desktop's frame list
// immediately, and then load the component into this blank (and now parent-less) frame
Reference < XComponentLoader > xLoader ( impl_createEmptyParentlessTask_nothrow ( ) , UNO_QUERY_THROW ) ;
2007-11-21 15:22:32 +00:00
Sequence < PropertyValue > aArgs ( 5 ) ;
aArgs [ 0 ] . Name = PROPERTY_ACTIVE_CONNECTION ;
aArgs [ 0 ] . Value < < = m_xConnection . getTyped ( ) ;
aArgs [ 1 ] . Name = PROPERTY_COMMAND ;
aArgs [ 1 ] . Value < < = m_xObjectAdapter - > getSQLCommand ( ) ;
aArgs [ 2 ] . Name = PROPERTY_COMMANDTYPE ;
aArgs [ 2 ] . Value < < = ( sal_Int32 ) CommandType : : COMMAND ;
aArgs [ 3 ] . Name = PROPERTY_ESCAPE_PROCESSING ;
aArgs [ 3 ] . Value < < = m_xObjectAdapter - > getEscapeProcessing ( ) ;
2013-11-15 11:05:19 +02:00
aArgs [ 4 ] . Name = " GraphicalDesign " ;
2007-11-21 15:22:32 +00:00
aArgs [ 4 ] . Value < < = m_xObjectAdapter - > getEscapeProcessing ( ) ;
2006-03-14 10:32:32 +00:00
Reference < XComponent > xQueryDesign = xLoader - > loadComponentFromURL (
2015-11-04 08:29:36 +02:00
" .component:DB/QueryDesign " ,
" _self " ,
2006-03-14 10:32:32 +00:00
FrameSearchFlag : : TASKS | FrameSearchFlag : : CREATE ,
aArgs
) ;
// remember this newly loaded component - we need to care for it e.g. when we're suspended
2014-06-13 17:49:59 +02:00
m_xDesigner . set ( xQueryDesign , css : : uno : : UNO_QUERY ) ;
2006-03-14 10:32:32 +00:00
OSL_ENSURE ( m_xDesigner . is ( ) | | ! xQueryDesign . is ( ) , " SQLCommandDesigner::impl_doOpenDesignerFrame_nothrow: the component is expected to be a controller! " ) ;
if ( m_xDesigner . is ( ) )
{
Reference < XPropertySet > xQueryDesignProps ( m_xDesigner , UNO_QUERY ) ;
OSL_ENSURE ( xQueryDesignProps . is ( ) , " SQLCommandDesigner::impl_doOpenDesignerFrame_nothrow: the controller should have properties! " ) ;
if ( xQueryDesignProps . is ( ) )
2007-11-21 15:22:32 +00:00
{
2006-03-14 10:32:32 +00:00
xQueryDesignProps - > addPropertyChangeListener ( PROPERTY_ACTIVECOMMAND , this ) ;
2007-11-21 15:22:32 +00:00
xQueryDesignProps - > addPropertyChangeListener ( PROPERTY_ESCAPE_PROCESSING , this ) ;
}
2006-03-14 10:32:32 +00:00
}
2014-04-10 19:59:38 +03:00
// get the frame which we just opened and set its title
2008-04-04 13:06:33 +00:00
Reference < XTitle > xTitle ( xQueryDesign , UNO_QUERY ) ;
if ( xTitle . is ( ) )
2006-03-14 10:32:32 +00:00
{
2017-06-11 20:56:30 +01:00
OUString sDisplayName = PcrRes ( RID_RSC_ENUM_COMMAND_TYPE [ CommandType : : COMMAND ] ) ;
xTitle - > setTitle ( sDisplayName ) ;
2006-03-14 10:32:32 +00:00
}
}
catch ( const Exception & )
{
2007-05-10 09:49:49 +00:00
DBG_UNHANDLED_EXCEPTION ( ) ;
2007-01-15 13:40:49 +00:00
m_xDesigner . clear ( ) ;
2006-03-14 10:32:32 +00:00
}
2012-09-22 01:51:12 -05:00
osl_atomic_decrement ( & m_refCount ) ;
2006-03-14 10:32:32 +00:00
}
2014-02-22 21:20:15 +01:00
2006-03-14 10:32:32 +00:00
Reference < XFrame > SQLCommandDesigner : : impl_createEmptyParentlessTask_nothrow ( ) const
{
OSL_PRECOND ( m_xORB . is ( ) , " SQLCommandDesigner::impl_createEmptyParentlessTask_nothrow: this will crash! " ) ;
Reference < XFrame > xFrame ;
try
{
2012-12-14 12:58:00 +02:00
Reference < XDesktop2 > xDesktop = Desktop : : create ( m_xContext ) ;
2006-03-14 10:32:32 +00:00
2012-12-14 12:58:00 +02:00
Reference < XFrames > xDesktopFramesCollection ( xDesktop - > getFrames ( ) , UNO_QUERY_THROW ) ;
2015-11-04 08:29:36 +02:00
xFrame = xDesktop - > findFrame ( " _blank " , FrameSearchFlag : : CREATE ) ;
2006-03-14 10:32:32 +00:00
OSL_ENSURE ( xFrame . is ( ) , " SQLCommandDesigner::impl_createEmptyParentlessTask_nothrow: could not create an empty frame! " ) ;
xDesktopFramesCollection - > remove ( xFrame ) ;
}
catch ( const Exception & )
{
2007-05-10 09:49:49 +00:00
DBG_UNHANDLED_EXCEPTION ( ) ;
2006-03-14 10:32:32 +00:00
}
return xFrame ;
}
2014-02-22 21:20:15 +01:00
2007-05-10 09:49:49 +00:00
void SQLCommandDesigner : : impl_closeDesigner_nothrow ( )
2006-03-14 10:32:32 +00:00
{
2017-03-02 12:27:41 +01:00
OSL_PRECOND ( isActive ( ) , " SQLCommandDesigner::impl_closeDesigner_nothrow: invalid call! " ) ;
2006-03-14 10:32:32 +00:00
// close it
try
{
2017-03-02 12:27:41 +01:00
// do not listen anymore...
2006-03-14 10:32:32 +00:00
Reference < XPropertySet > xProps ( m_xDesigner , UNO_QUERY ) ;
if ( xProps . is ( ) )
xProps - > removePropertyChangeListener ( PROPERTY_ACTIVECOMMAND , this ) ;
// we need to close the frame via the "user interface", by dispatching a close command,
// instead of calling XCloseable::close directly. The latter method would also close
// the frame, but not care for things like shutting down the office when the last
// frame is gone ...
2017-01-30 16:38:54 +02:00
const UnoURL aCloseURL ( " .uno:CloseDoc " ,
2006-03-14 10:32:32 +00:00
Reference < XMultiServiceFactory > ( m_xORB , UNO_QUERY ) ) ;
Reference < XDispatchProvider > xProvider ( m_xDesigner - > getFrame ( ) , UNO_QUERY_THROW ) ;
2015-11-04 08:29:36 +02:00
Reference < XDispatch > xDispatch ( xProvider - > queryDispatch ( aCloseURL , " _top " , FrameSearchFlag : : SELF ) ) ;
2007-05-10 09:49:49 +00:00
OSL_ENSURE ( xDispatch . is ( ) , " SQLCommandDesigner::impl_closeDesigner_nothrow: no dispatcher for the CloseDoc command! " ) ;
2006-03-14 10:32:32 +00:00
if ( xDispatch . is ( ) )
{
xDispatch - > dispatch ( aCloseURL , Sequence < PropertyValue > ( ) ) ;
}
else
{
// fallback: use the XCloseable::close (with all possible disadvantages)
Reference < XCloseable > xClose ( m_xDesigner - > getFrame ( ) , UNO_QUERY ) ;
if ( xClose . is ( ) )
2016-04-20 17:16:53 +02:00
xClose - > close ( true ) ;
2006-03-14 10:32:32 +00:00
}
}
catch ( const Exception & )
{
2007-05-10 09:49:49 +00:00
DBG_UNHANDLED_EXCEPTION ( ) ;
2006-03-14 10:32:32 +00:00
}
2007-11-21 15:22:32 +00:00
m_xDesigner . clear ( ) ;
2006-03-14 10:32:32 +00:00
}
2014-02-22 21:20:15 +01:00
2006-03-14 10:32:32 +00:00
bool SQLCommandDesigner : : impl_trySuspendDesigner_nothrow ( ) const
{
OSL_PRECOND ( isActive ( ) , " SQLCommandDesigner::impl_trySuspendDesigner_nothrow: no active designer, this will crash! " ) ;
2014-04-30 11:46:15 +02:00
bool bAllow = true ;
2006-03-14 10:32:32 +00:00
try
{
2016-04-20 17:16:53 +02:00
bAllow = m_xDesigner - > suspend ( true ) ;
2006-03-14 10:32:32 +00:00
}
catch ( const Exception & )
{
2007-05-10 09:49:49 +00:00
DBG_UNHANDLED_EXCEPTION ( ) ;
2006-03-14 10:32:32 +00:00
}
return bAllow ;
}
2007-11-21 15:22:32 +00:00
2014-02-25 18:36:00 +01:00
2006-03-14 10:32:32 +00:00
} // namespace pcr
2014-02-25 18:36:00 +01:00
2006-03-14 10:32:32 +00:00
2010-10-12 15:57:08 +02:00
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */