2010-10-12 15:59:03 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-06-14 17:39:53 +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-09-17 06:23:48 +00:00
|
|
|
|
2001-02-05 08:26:47 +00:00
|
|
|
#include "QueryViewSwitch.hxx"
|
|
|
|
#include "QueryDesignView.hxx"
|
|
|
|
#include "QueryTextView.hxx"
|
2001-08-23 13:39:09 +00:00
|
|
|
#include "querycontainerwindow.hxx"
|
2002-08-19 07:01:32 +00:00
|
|
|
#include "dbu_qry.hrc"
|
2001-02-05 08:26:47 +00:00
|
|
|
#include "browserids.hxx"
|
|
|
|
#include "adtabdlg.hxx"
|
|
|
|
#include "querycontroller.hxx"
|
2001-04-18 12:20:48 +00:00
|
|
|
#include "sqledit.hxx"
|
2001-02-05 08:26:47 +00:00
|
|
|
|
|
|
|
using namespace dbaui;
|
|
|
|
using namespace ::com::sun::star::uno;
|
|
|
|
using namespace ::com::sun::star::lang;
|
|
|
|
|
2006-06-20 02:27:13 +00:00
|
|
|
DBG_NAME(OQueryViewSwitch)
|
2008-06-25 11:53:48 +00:00
|
|
|
OQueryViewSwitch::OQueryViewSwitch(OQueryContainerWindow* _pParent, OQueryController& _rController,const Reference< XMultiServiceFactory >& _rFactory)
|
2002-07-08 10:47:17 +00:00
|
|
|
: m_bAddTableDialogWasVisible(sal_False)
|
2001-02-05 08:26:47 +00:00
|
|
|
{
|
2001-08-15 12:19:03 +00:00
|
|
|
DBG_CTOR(OQueryViewSwitch,NULL);
|
2001-02-28 09:18:26 +00:00
|
|
|
|
2001-08-23 13:39:09 +00:00
|
|
|
m_pTextView = new OQueryTextView(_pParent);
|
2008-06-25 11:53:48 +00:00
|
|
|
m_pDesignView = new OQueryDesignView( _pParent, _rController, _rFactory );
|
2001-02-05 08:26:47 +00:00
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
OQueryViewSwitch::~OQueryViewSwitch()
|
|
|
|
{
|
2004-08-02 15:13:39 +00:00
|
|
|
DBG_DTOR(OQueryViewSwitch,NULL);
|
2002-05-29 07:31:08 +00:00
|
|
|
{
|
2011-09-22 15:00:08 +01:00
|
|
|
SAL_WNODEPRECATED_DECLARATIONS_PUSH
|
2002-05-29 07:31:08 +00:00
|
|
|
::std::auto_ptr<Window> aTemp(m_pTextView);
|
2011-09-22 15:00:08 +01:00
|
|
|
SAL_WNODEPRECATED_DECLARATIONS_POP
|
2002-05-29 07:31:08 +00:00
|
|
|
m_pTextView = NULL;
|
|
|
|
}
|
|
|
|
{
|
2011-09-22 15:00:08 +01:00
|
|
|
SAL_WNODEPRECATED_DECLARATIONS_PUSH
|
2002-05-29 07:31:08 +00:00
|
|
|
::std::auto_ptr<Window> aTemp(m_pDesignView);
|
2011-09-22 15:00:08 +01:00
|
|
|
SAL_WNODEPRECATED_DECLARATIONS_POP
|
2002-05-29 07:31:08 +00:00
|
|
|
m_pDesignView = NULL;
|
|
|
|
}
|
2001-02-05 08:26:47 +00:00
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
2001-08-23 13:39:09 +00:00
|
|
|
void OQueryViewSwitch::Construct()
|
2001-02-05 08:26:47 +00:00
|
|
|
{
|
2001-08-23 13:39:09 +00:00
|
|
|
m_pDesignView->Construct( );
|
2001-02-05 08:26:47 +00:00
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
void OQueryViewSwitch::initialize()
|
|
|
|
{
|
2002-05-06 08:52:47 +00:00
|
|
|
// initially be in SQL mode
|
|
|
|
m_pTextView->Show();
|
2001-02-05 08:26:47 +00:00
|
|
|
m_pDesignView->initialize();
|
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
2001-08-23 13:39:09 +00:00
|
|
|
void OQueryViewSwitch::resizeDocumentView(Rectangle& _rPlayground)
|
2001-02-05 08:26:47 +00:00
|
|
|
{
|
2001-08-15 12:43:46 +00:00
|
|
|
m_pTextView->SetPosSizePixel( _rPlayground.TopLeft(), _rPlayground.GetSize() );
|
|
|
|
m_pDesignView->SetPosSizePixel( _rPlayground.TopLeft(), _rPlayground.GetSize() );
|
2001-02-05 08:26:47 +00:00
|
|
|
|
2001-08-15 12:43:46 +00:00
|
|
|
// just for completeness: there is no space left, we occupied it all ...
|
|
|
|
_rPlayground.SetPos( _rPlayground.BottomRight() );
|
|
|
|
_rPlayground.SetSize( Size( 0, 0 ) );
|
2001-02-05 08:26:47 +00:00
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
2001-09-27 05:19:05 +00:00
|
|
|
sal_Bool OQueryViewSwitch::checkStatement()
|
|
|
|
{
|
|
|
|
if(m_pTextView->IsVisible())
|
|
|
|
return m_pTextView->checkStatement();
|
|
|
|
return m_pDesignView->checkStatement();
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
2001-02-05 08:26:47 +00:00
|
|
|
::rtl::OUString OQueryViewSwitch::getStatement()
|
|
|
|
{
|
|
|
|
if(m_pTextView->IsVisible())
|
|
|
|
return m_pTextView->getStatement();
|
|
|
|
return m_pDesignView->getStatement();
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
void OQueryViewSwitch::setReadOnly(sal_Bool _bReadOnly)
|
|
|
|
{
|
|
|
|
if(m_pTextView->IsVisible())
|
|
|
|
m_pTextView->setReadOnly(_bReadOnly);
|
|
|
|
else
|
|
|
|
m_pDesignView->setReadOnly(_bReadOnly);
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
void OQueryViewSwitch::clear()
|
|
|
|
{
|
|
|
|
if(m_pTextView->IsVisible())
|
|
|
|
m_pTextView->clear();
|
|
|
|
else
|
|
|
|
m_pDesignView->clear();
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
2002-02-11 12:02:08 +00:00
|
|
|
void OQueryViewSwitch::GrabFocus()
|
|
|
|
{
|
|
|
|
if ( m_pTextView && m_pTextView->IsVisible() )
|
|
|
|
m_pTextView->GrabFocus();
|
|
|
|
else if ( m_pDesignView && m_pDesignView->IsVisible() )
|
|
|
|
m_pDesignView->GrabFocus();
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
2001-02-05 08:26:47 +00:00
|
|
|
void OQueryViewSwitch::setStatement(const ::rtl::OUString& _rsStatement)
|
|
|
|
{
|
|
|
|
if(m_pTextView->IsVisible())
|
|
|
|
m_pTextView->setStatement(_rsStatement);
|
|
|
|
else
|
|
|
|
m_pDesignView->setStatement(_rsStatement);
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
void OQueryViewSwitch::copy()
|
|
|
|
{
|
|
|
|
if(m_pTextView->IsVisible())
|
|
|
|
m_pTextView->copy();
|
|
|
|
else
|
|
|
|
m_pDesignView->copy();
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
sal_Bool OQueryViewSwitch::isCutAllowed()
|
|
|
|
{
|
|
|
|
if(m_pTextView->IsVisible())
|
|
|
|
return m_pTextView->isCutAllowed();
|
|
|
|
return m_pDesignView->isCutAllowed();
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
2001-04-18 12:20:48 +00:00
|
|
|
sal_Bool OQueryViewSwitch::isCopyAllowed()
|
|
|
|
{
|
|
|
|
if(m_pTextView->IsVisible())
|
|
|
|
return m_pTextView->isCopyAllowed();
|
|
|
|
return m_pDesignView->isCopyAllowed();
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
sal_Bool OQueryViewSwitch::isPasteAllowed()
|
|
|
|
{
|
|
|
|
if(m_pTextView->IsVisible())
|
|
|
|
return m_pTextView->isPasteAllowed();
|
|
|
|
return m_pDesignView->isPasteAllowed();
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
2001-02-05 08:26:47 +00:00
|
|
|
void OQueryViewSwitch::cut()
|
|
|
|
{
|
|
|
|
if(m_pTextView->IsVisible())
|
|
|
|
m_pTextView->cut();
|
|
|
|
else
|
|
|
|
m_pDesignView->cut();
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
void OQueryViewSwitch::paste()
|
|
|
|
{
|
|
|
|
if(m_pTextView->IsVisible())
|
|
|
|
m_pTextView->paste();
|
|
|
|
else
|
|
|
|
m_pDesignView->paste();
|
|
|
|
}
|
2001-08-23 13:39:09 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
OQueryContainerWindow* OQueryViewSwitch::getContainer() const
|
|
|
|
{
|
|
|
|
Window* pDesignParent = getDesignView() ? getDesignView()->GetParent() : NULL;
|
|
|
|
return static_cast< OQueryContainerWindow* >( pDesignParent );
|
|
|
|
}
|
|
|
|
|
2001-02-05 08:26:47 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
2010-02-16 15:21:07 +01:00
|
|
|
void OQueryViewSwitch::impl_forceSQLView()
|
2001-02-05 08:26:47 +00:00
|
|
|
{
|
2006-07-10 14:42:03 +00:00
|
|
|
OAddTableDlg* pAddTabDialog( getAddTableDialog() );
|
|
|
|
|
2010-02-16 15:21:07 +01:00
|
|
|
// hide the "Add Table" dialog
|
|
|
|
m_bAddTableDialogWasVisible = pAddTabDialog ? pAddTabDialog->IsVisible() : false;
|
|
|
|
if ( m_bAddTableDialogWasVisible )
|
|
|
|
pAddTabDialog->Hide();
|
|
|
|
|
|
|
|
// tell the views they're in/active
|
|
|
|
m_pDesignView->stopTimer();
|
|
|
|
m_pTextView->getSqlEdit()->startTimer();
|
|
|
|
|
|
|
|
// set the most recent statement at the text view
|
|
|
|
m_pTextView->clear();
|
|
|
|
m_pTextView->setStatement(static_cast<OQueryController&>(m_pDesignView->getController()).getStatement());
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
void OQueryViewSwitch::forceInitialView()
|
|
|
|
{
|
|
|
|
OQueryController& rQueryController( static_cast< OQueryController& >( m_pDesignView->getController() ) );
|
|
|
|
const sal_Bool bGraphicalDesign = rQueryController.isGraphicalDesign();
|
2008-12-01 12:31:27 +00:00
|
|
|
if ( !bGraphicalDesign )
|
2010-02-16 15:21:07 +01:00
|
|
|
impl_forceSQLView();
|
|
|
|
else
|
2002-07-08 10:47:17 +00:00
|
|
|
{
|
2010-02-16 15:21:07 +01:00
|
|
|
// tell the text view it's inactive now
|
|
|
|
m_pTextView->getSqlEdit()->stopTimer();
|
|
|
|
|
|
|
|
// update the "Add Table" dialog
|
|
|
|
OAddTableDlg* pAddTabDialog( getAddTableDialog() );
|
|
|
|
if ( pAddTabDialog )
|
|
|
|
pAddTabDialog->Update();
|
2001-08-23 13:39:09 +00:00
|
|
|
|
2010-02-16 15:21:07 +01:00
|
|
|
// initialize the design view
|
|
|
|
m_pDesignView->initByFieldDescriptions( rQueryController.getFieldInformation() );
|
2001-08-23 13:39:09 +00:00
|
|
|
|
2010-02-16 15:21:07 +01:00
|
|
|
// tell the design view it's active now
|
|
|
|
m_pDesignView->startTimer();
|
|
|
|
}
|
|
|
|
|
|
|
|
impl_postViewSwitch( bGraphicalDesign, true );
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
bool OQueryViewSwitch::switchView( ::dbtools::SQLExceptionInfo* _pErrorInfo )
|
|
|
|
{
|
|
|
|
sal_Bool bRet = sal_True;
|
|
|
|
sal_Bool bGraphicalDesign = static_cast<OQueryController&>(m_pDesignView->getController()).isGraphicalDesign();
|
|
|
|
|
|
|
|
if ( !bGraphicalDesign )
|
|
|
|
{
|
|
|
|
impl_forceSQLView();
|
2001-02-05 08:26:47 +00:00
|
|
|
}
|
2001-08-23 13:39:09 +00:00
|
|
|
else
|
2001-02-05 08:26:47 +00:00
|
|
|
{
|
2008-12-01 12:31:27 +00:00
|
|
|
// tell the text view it's inactive now
|
2001-04-18 12:20:48 +00:00
|
|
|
m_pTextView->getSqlEdit()->stopTimer();
|
2006-07-10 14:42:03 +00:00
|
|
|
|
2008-12-01 12:31:27 +00:00
|
|
|
// update the "Add Table" dialog
|
2010-02-16 15:21:07 +01:00
|
|
|
OAddTableDlg* pAddTabDialog( getAddTableDialog() );
|
2006-07-10 14:42:03 +00:00
|
|
|
if ( pAddTabDialog )
|
|
|
|
pAddTabDialog->Update();
|
2001-08-23 13:39:09 +00:00
|
|
|
|
2008-12-01 12:31:27 +00:00
|
|
|
// initialize the design view
|
|
|
|
bRet = m_pDesignView->initByParseIterator( _pErrorInfo );
|
|
|
|
|
|
|
|
// tell the design view it's active now
|
2001-04-18 12:20:48 +00:00
|
|
|
m_pDesignView->startTimer();
|
2001-02-05 08:26:47 +00:00
|
|
|
}
|
2001-08-23 13:39:09 +00:00
|
|
|
|
2010-02-16 15:21:07 +01:00
|
|
|
return impl_postViewSwitch( bGraphicalDesign, bRet );
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
bool OQueryViewSwitch::impl_postViewSwitch( const bool i_bGraphicalDesign, const bool i_bSuccess )
|
|
|
|
{
|
|
|
|
if ( i_bSuccess )
|
2002-05-06 08:52:47 +00:00
|
|
|
{
|
2010-02-16 15:21:07 +01:00
|
|
|
m_pTextView->Show ( !i_bGraphicalDesign );
|
|
|
|
m_pDesignView->Show ( i_bGraphicalDesign );
|
|
|
|
OAddTableDlg* pAddTabDialog( getAddTableDialog() );
|
|
|
|
if ( pAddTabDialog )
|
|
|
|
if ( i_bGraphicalDesign && m_bAddTableDialogWasVisible )
|
|
|
|
pAddTabDialog->Show();
|
2003-04-28 14:49:12 +00:00
|
|
|
|
|
|
|
GrabFocus();
|
2002-05-06 08:52:47 +00:00
|
|
|
}
|
|
|
|
|
2010-02-16 15:21:07 +01:00
|
|
|
OQueryContainerWindow* pContainer = getContainer();
|
2001-08-23 13:39:09 +00:00
|
|
|
if ( pContainer )
|
|
|
|
pContainer->Resize();
|
2001-04-18 12:20:48 +00:00
|
|
|
|
2010-11-25 14:28:03 +01:00
|
|
|
m_pDesignView->getController().ClearUndoManager();
|
2008-06-25 11:53:48 +00:00
|
|
|
m_pDesignView->getController().InvalidateAll();
|
2002-05-06 08:52:47 +00:00
|
|
|
|
2010-02-16 15:21:07 +01:00
|
|
|
return i_bSuccess;
|
2001-02-05 08:26:47 +00:00
|
|
|
}
|
2010-02-16 15:21:07 +01:00
|
|
|
|
2001-02-05 08:26:47 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
OAddTableDlg* OQueryViewSwitch::getAddTableDialog()
|
|
|
|
{
|
2006-07-10 14:42:03 +00:00
|
|
|
if ( !m_pDesignView )
|
|
|
|
return NULL;
|
2008-06-25 11:53:48 +00:00
|
|
|
return m_pDesignView->getController().getAddTableDialog();
|
2001-02-05 08:26:47 +00:00
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
sal_Bool OQueryViewSwitch::isSlotEnabled(sal_Int32 _nSlotId)
|
|
|
|
{
|
|
|
|
return m_pDesignView->isSlotEnabled(_nSlotId);
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
void OQueryViewSwitch::setSlotEnabled(sal_Int32 _nSlotId,sal_Bool _bEnable)
|
|
|
|
{
|
|
|
|
m_pDesignView->setSlotEnabled(_nSlotId,_bEnable);
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
2001-02-05 15:17:40 +00:00
|
|
|
void OQueryViewSwitch::SaveUIConfig()
|
|
|
|
{
|
|
|
|
if(m_pDesignView->IsVisible())
|
|
|
|
m_pDesignView->SaveUIConfig();
|
|
|
|
}
|
2001-02-28 09:18:26 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
void OQueryViewSwitch::SetPosSizePixel( Point _rPt,Size _rSize)
|
|
|
|
{
|
|
|
|
m_pDesignView->SetPosSizePixel( _rPt,_rSize);
|
2001-08-23 13:39:09 +00:00
|
|
|
m_pDesignView->Resize();
|
2001-02-28 09:18:26 +00:00
|
|
|
m_pTextView->SetPosSizePixel( _rPt,_rSize);
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
Reference< XMultiServiceFactory > OQueryViewSwitch::getORB() const
|
|
|
|
{
|
|
|
|
return m_pDesignView->getORB();
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
2008-12-01 12:31:27 +00:00
|
|
|
bool OQueryViewSwitch::reset( ::dbtools::SQLExceptionInfo* _pErrorInfo )
|
2001-10-23 11:30:27 +00:00
|
|
|
{
|
|
|
|
m_pDesignView->reset();
|
2008-12-01 12:31:27 +00:00
|
|
|
if ( !m_pDesignView->initByParseIterator( _pErrorInfo ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if ( switchView( _pErrorInfo ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
2001-10-23 11:30:27 +00:00
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
void OQueryViewSwitch::setNoneVisbleRow(sal_Int32 _nRows)
|
|
|
|
{
|
|
|
|
if(m_pDesignView)
|
|
|
|
m_pDesignView->setNoneVisbleRow(_nRows);
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
2010-10-12 15:59:03 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|