2010-10-12 15:59:03 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2001-01-09 15:11:54 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-10 13:21:45 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2001-01-09 15:11:54 +00:00
|
|
|
*
|
2010-02-12 15:01:35 +01:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2001-01-09 15:11:54 +00:00
|
|
|
*
|
2008-04-10 13:21:45 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2001-01-09 15:11:54 +00:00
|
|
|
*
|
2008-04-10 13:21:45 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2001-01-09 15:11:54 +00:00
|
|
|
*
|
2008-04-10 13:21:45 +00:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2001-01-09 15:11:54 +00:00
|
|
|
*
|
2008-04-10 13:21:45 +00:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2001-01-09 15:11:54 +00:00
|
|
|
*
|
2008-04-10 13:21:45 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2001-01-09 15:11:54 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
2006-09-17 06:02:29 +00:00
|
|
|
|
2012-01-25 18:18:18 +01:00
|
|
|
#include "sal/config.h"
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
#include "com/sun/star/beans/XMultiPropertySet.hpp"
|
|
|
|
#include "com/sun/star/beans/XPropertiesChangeListener.hpp"
|
|
|
|
#include "officecfg/Office/Common.hxx"
|
2001-01-09 15:11:54 +00:00
|
|
|
#include "sqledit.hxx"
|
|
|
|
#include "QueryTextView.hxx"
|
2001-08-23 13:47:34 +00:00
|
|
|
#include "querycontainerwindow.hxx"
|
2001-01-09 15:11:54 +00:00
|
|
|
#include <tools/debug.hxx>
|
|
|
|
#include "dbaccess_helpid.hrc"
|
|
|
|
#include "browserids.hxx"
|
|
|
|
#include "querycontroller.hxx"
|
|
|
|
#include "undosqledit.hxx"
|
2001-02-28 09:01:54 +00:00
|
|
|
#include "QueryDesignView.hxx"
|
2008-11-28 11:39:37 +00:00
|
|
|
|
2009-10-16 00:05:16 +02:00
|
|
|
#include <svl/smplhint.hxx>
|
2008-11-28 11:39:37 +00:00
|
|
|
|
2012-04-21 01:30:38 +02:00
|
|
|
namespace css = ::com::sun::star;
|
2012-01-25 18:18:18 +01:00
|
|
|
|
2001-01-09 15:11:54 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// OSqlEdit
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
using namespace dbaui;
|
|
|
|
|
2012-01-25 18:18:18 +01:00
|
|
|
class OSqlEdit::ChangesListener:
|
|
|
|
public cppu::WeakImplHelper1< css::beans::XPropertiesChangeListener >
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ChangesListener(OSqlEdit & editor): editor_(editor) {}
|
|
|
|
|
|
|
|
private:
|
|
|
|
virtual ~ChangesListener() {}
|
|
|
|
|
2012-01-29 18:20:29 +07:00
|
|
|
virtual void SAL_CALL disposing(css::lang::EventObject const &)
|
2012-01-25 18:18:18 +01:00
|
|
|
throw (css::uno::RuntimeException)
|
|
|
|
{
|
|
|
|
osl::MutexGuard g(editor_.m_mutex);
|
|
|
|
editor_.m_notifier.clear();
|
|
|
|
}
|
|
|
|
|
2012-01-29 18:20:29 +07:00
|
|
|
virtual void SAL_CALL propertiesChange(
|
2012-01-25 18:18:18 +01:00
|
|
|
css::uno::Sequence< css::beans::PropertyChangeEvent > const &)
|
|
|
|
throw (css::uno::RuntimeException)
|
|
|
|
{
|
|
|
|
SolarMutexGuard g;
|
|
|
|
editor_.ImplSetFont();
|
|
|
|
}
|
|
|
|
|
|
|
|
OSqlEdit & editor_;
|
|
|
|
};
|
|
|
|
|
2006-06-20 02:00:45 +00:00
|
|
|
DBG_NAME(OSqlEdit)
|
2001-01-09 15:11:54 +00:00
|
|
|
OSqlEdit::OSqlEdit( OQueryTextView* pParent, WinBits nWinStyle ) :
|
2008-11-28 11:39:37 +00:00
|
|
|
MultiLineEditSyntaxHighlight( pParent, nWinStyle )
|
2006-06-20 02:00:45 +00:00
|
|
|
,m_pView(pParent)
|
2001-01-09 15:11:54 +00:00
|
|
|
,m_bAccelAction( sal_False )
|
2001-04-18 12:20:48 +00:00
|
|
|
,m_bStopTimer(sal_False )
|
2001-01-09 15:11:54 +00:00
|
|
|
{
|
|
|
|
DBG_CTOR(OSqlEdit,NULL);
|
|
|
|
SetHelpId( HID_CTL_QRYSQLEDIT );
|
|
|
|
SetModifyHdl( LINK(this, OSqlEdit, ModifyHdl) );
|
|
|
|
|
|
|
|
m_timerUndoActionCreation.SetTimeout(1000);
|
|
|
|
m_timerUndoActionCreation.SetTimeoutHdl(LINK(this, OSqlEdit, OnUndoActionTimer));
|
|
|
|
|
|
|
|
m_timerInvalidate.SetTimeout(200);
|
|
|
|
m_timerInvalidate.SetTimeoutHdl(LINK(this, OSqlEdit, OnInvalidateTimer));
|
|
|
|
m_timerInvalidate.Start();
|
2008-11-28 11:39:37 +00:00
|
|
|
|
|
|
|
ImplSetFont();
|
2012-01-25 18:18:18 +01:00
|
|
|
// Listen for change of Font and Color Settings:
|
|
|
|
// Using "this" in ctor is a little fishy, but should work here at least as
|
|
|
|
// long as there are no derivations:
|
|
|
|
m_listener = new ChangesListener(*this);
|
|
|
|
css::uno::Reference< css::beans::XMultiPropertySet > n(
|
2012-01-31 17:25:42 +01:00
|
|
|
officecfg::Office::Common::Font::SourceViewFont::get(),
|
2012-01-25 18:18:18 +01:00
|
|
|
css::uno::UNO_QUERY_THROW);
|
|
|
|
{
|
|
|
|
osl::MutexGuard g(m_mutex);
|
|
|
|
m_notifier = n;
|
|
|
|
}
|
|
|
|
css::uno::Sequence< rtl::OUString > s(2);
|
|
|
|
s[0] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FontHeight"));
|
|
|
|
s[1] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FontName"));
|
|
|
|
n->addPropertiesChangeListener(s, m_listener.get());
|
2009-10-16 00:05:16 +02:00
|
|
|
m_ColorConfig.AddListener(this);
|
2009-02-13 07:10:18 +00:00
|
|
|
|
|
|
|
//#i97044#
|
2011-01-14 15:00:11 +01:00
|
|
|
EnableFocusSelectionHide( sal_False );
|
2001-01-09 15:11:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
OSqlEdit::~OSqlEdit()
|
|
|
|
{
|
2004-08-02 14:36:57 +00:00
|
|
|
DBG_DTOR(OSqlEdit,NULL);
|
2001-01-09 15:11:54 +00:00
|
|
|
if (m_timerUndoActionCreation.IsActive())
|
|
|
|
m_timerUndoActionCreation.Stop();
|
2012-01-25 18:18:18 +01:00
|
|
|
css::uno::Reference< css::beans::XMultiPropertySet > n;
|
|
|
|
{
|
|
|
|
osl::MutexGuard g(m_mutex);
|
|
|
|
n = m_notifier;
|
|
|
|
}
|
|
|
|
if (n.is()) {
|
|
|
|
n->removePropertiesChangeListener(m_listener.get());
|
|
|
|
}
|
2009-10-16 00:05:16 +02:00
|
|
|
m_ColorConfig.RemoveListener(this);
|
2001-01-09 15:11:54 +00:00
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void OSqlEdit::KeyInput( const KeyEvent& rKEvt )
|
|
|
|
{
|
|
|
|
DBG_CHKTHIS(OSqlEdit,NULL);
|
2010-01-27 15:20:45 +01:00
|
|
|
OJoinController& rController = m_pView->getContainerWindow()->getDesignView()->getController();
|
|
|
|
rController.InvalidateFeature(SID_CUT);
|
|
|
|
rController.InvalidateFeature(SID_COPY);
|
2001-01-09 15:11:54 +00:00
|
|
|
|
|
|
|
// Ist dies ein Cut, Copy, Paste Event?
|
|
|
|
KeyFuncType aKeyFunc = rKEvt.GetKeyCode().GetFunction();
|
|
|
|
if( (aKeyFunc==KEYFUNC_CUT)||(aKeyFunc==KEYFUNC_COPY)||(aKeyFunc==KEYFUNC_PASTE) )
|
|
|
|
m_bAccelAction = sal_True;
|
|
|
|
|
2008-11-28 11:39:37 +00:00
|
|
|
MultiLineEditSyntaxHighlight::KeyInput( rKEvt );
|
2001-01-09 15:11:54 +00:00
|
|
|
|
|
|
|
if( m_bAccelAction )
|
|
|
|
m_bAccelAction = sal_False;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
sal_Bool OSqlEdit::IsInAccelAct()
|
|
|
|
{
|
|
|
|
DBG_CHKTHIS(OSqlEdit,NULL);
|
|
|
|
// Das Cut, Copy, Paste per Accel. fuehrt neben der Aktion im Edit im View
|
|
|
|
// auch die entsprechenden Slots aus. Die Aktionen finden also zweimal statt.
|
|
|
|
// Um dies zu verhindern, kann im View beim SlotExec diese Funktion
|
|
|
|
// aufgerufen werden.
|
|
|
|
|
|
|
|
return m_bAccelAction;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void OSqlEdit::GetFocus()
|
|
|
|
{
|
|
|
|
DBG_CHKTHIS(OSqlEdit,NULL);
|
2004-08-02 14:36:57 +00:00
|
|
|
m_strOrigText =GetText();
|
2008-11-28 11:39:37 +00:00
|
|
|
MultiLineEditSyntaxHighlight::GetFocus();
|
2001-01-09 15:11:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2012-03-01 18:00:32 +01:00
|
|
|
IMPL_LINK_NOARG(OSqlEdit, OnUndoActionTimer)
|
2001-01-09 15:11:54 +00:00
|
|
|
{
|
2004-08-02 14:36:57 +00:00
|
|
|
String aText =GetText();
|
2001-01-09 15:11:54 +00:00
|
|
|
if(aText != m_strOrigText)
|
|
|
|
{
|
2010-01-27 15:20:45 +01:00
|
|
|
OJoinController& rController = m_pView->getContainerWindow()->getDesignView()->getController();
|
2010-11-17 09:11:03 +01:00
|
|
|
SfxUndoManager& rUndoMgr = rController.GetUndoManager();
|
2001-01-09 15:11:54 +00:00
|
|
|
OSqlEditUndoAct* pUndoAct = new OSqlEditUndoAct( this );
|
|
|
|
|
|
|
|
pUndoAct->SetOriginalText( m_strOrigText );
|
2010-11-17 09:11:03 +01:00
|
|
|
rUndoMgr.AddUndoAction( pUndoAct );
|
2001-01-09 15:11:54 +00:00
|
|
|
|
2010-01-27 15:20:45 +01:00
|
|
|
rController.InvalidateFeature(SID_UNDO);
|
|
|
|
rController.InvalidateFeature(SID_REDO);
|
2001-01-09 15:11:54 +00:00
|
|
|
|
2004-08-02 14:36:57 +00:00
|
|
|
m_strOrigText =aText;
|
2001-01-09 15:11:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0L;
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
2012-03-01 18:00:32 +01:00
|
|
|
IMPL_LINK_NOARG(OSqlEdit, OnInvalidateTimer)
|
2001-01-09 15:11:54 +00:00
|
|
|
{
|
2010-01-27 15:20:45 +01:00
|
|
|
OJoinController& rController = m_pView->getContainerWindow()->getDesignView()->getController();
|
|
|
|
rController.InvalidateFeature(SID_CUT);
|
|
|
|
rController.InvalidateFeature(SID_COPY);
|
2001-04-18 12:20:48 +00:00
|
|
|
if(!m_bStopTimer)
|
|
|
|
m_timerInvalidate.Start();
|
2001-01-09 15:11:54 +00:00
|
|
|
return 0L;
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
2006-06-20 02:00:45 +00:00
|
|
|
IMPL_LINK(OSqlEdit, ModifyHdl, void*, /*EMPTYTAG*/)
|
2001-01-09 15:11:54 +00:00
|
|
|
{
|
|
|
|
if (m_timerUndoActionCreation.IsActive())
|
|
|
|
m_timerUndoActionCreation.Stop();
|
|
|
|
m_timerUndoActionCreation.Start();
|
|
|
|
|
2010-01-27 15:20:45 +01:00
|
|
|
OJoinController& rController = m_pView->getContainerWindow()->getDesignView()->getController();
|
|
|
|
if (!rController.isModified())
|
|
|
|
rController.setModified( sal_True );
|
2001-01-09 15:11:54 +00:00
|
|
|
|
2010-01-27 15:20:45 +01:00
|
|
|
rController.InvalidateFeature(SID_SBA_QRY_EXECUTE);
|
|
|
|
rController.InvalidateFeature(SID_CUT);
|
|
|
|
rController.InvalidateFeature(SID_COPY);
|
2001-01-09 15:11:54 +00:00
|
|
|
|
|
|
|
m_lnkTextModifyHdl.Call(NULL);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2007-11-21 14:51:26 +00:00
|
|
|
void OSqlEdit::SetText(const String& rNewText)
|
2001-01-09 15:11:54 +00:00
|
|
|
{
|
|
|
|
DBG_CHKTHIS(OSqlEdit,NULL);
|
|
|
|
if (m_timerUndoActionCreation.IsActive())
|
|
|
|
{ // die noch anstehenden Undo-Action erzeugen
|
|
|
|
m_timerUndoActionCreation.Stop();
|
|
|
|
LINK(this, OSqlEdit, OnUndoActionTimer).Call(NULL);
|
|
|
|
}
|
|
|
|
|
2008-11-28 11:39:37 +00:00
|
|
|
MultiLineEditSyntaxHighlight::SetText(rNewText);
|
2004-08-02 14:36:57 +00:00
|
|
|
m_strOrigText =rNewText;
|
2001-01-09 15:11:54 +00:00
|
|
|
}
|
2001-04-18 12:20:48 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
void OSqlEdit::stopTimer()
|
|
|
|
{
|
|
|
|
m_bStopTimer = sal_True;
|
|
|
|
if (m_timerInvalidate.IsActive())
|
|
|
|
m_timerInvalidate.Stop();
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
void OSqlEdit::startTimer()
|
|
|
|
{
|
|
|
|
m_bStopTimer = sal_False;
|
|
|
|
if (!m_timerInvalidate.IsActive())
|
|
|
|
m_timerInvalidate.Start();
|
|
|
|
}
|
2001-01-09 15:11:54 +00:00
|
|
|
|
2009-10-16 00:05:16 +02:00
|
|
|
void OSqlEdit::ConfigurationChanged( utl::ConfigurationBroadcaster* pOption, sal_uInt32 )
|
2009-10-06 07:38:24 +02:00
|
|
|
{
|
2012-01-25 18:18:18 +01:00
|
|
|
assert( pOption == &m_ColorConfig );
|
|
|
|
(void) pOption; // avoid warnings
|
|
|
|
MultiLineEditSyntaxHighlight::UpdateData();
|
2009-10-06 07:38:24 +02:00
|
|
|
}
|
|
|
|
|
2008-11-28 11:39:37 +00:00
|
|
|
void OSqlEdit::ImplSetFont()
|
|
|
|
{
|
|
|
|
AllSettings aSettings = GetSettings();
|
|
|
|
StyleSettings aStyleSettings = aSettings.GetStyleSettings();
|
2012-01-25 18:18:18 +01:00
|
|
|
rtl::OUString sFontName(
|
2012-01-31 17:25:42 +01:00
|
|
|
officecfg::Office::Common::Font::SourceViewFont::FontName::get().
|
2012-01-30 12:19:11 +01:00
|
|
|
get_value_or( rtl::OUString() ) );
|
2012-01-25 18:18:18 +01:00
|
|
|
if ( sFontName.isEmpty() )
|
2008-11-28 11:39:37 +00:00
|
|
|
{
|
|
|
|
Font aTmpFont( OutputDevice::GetDefaultFont( DEFAULTFONT_FIXED, Application::GetSettings().GetUILanguage(), 0 , this ) );
|
|
|
|
sFontName = aTmpFont.GetName();
|
|
|
|
}
|
2012-01-25 18:18:18 +01:00
|
|
|
Size aFontSize(
|
2012-01-31 17:25:42 +01:00
|
|
|
0, officecfg::Office::Common::Font::SourceViewFont::FontHeight::get() );
|
2008-11-28 11:39:37 +00:00
|
|
|
Font aFont( sFontName, aFontSize );
|
|
|
|
aStyleSettings.SetFieldFont(aFont);
|
|
|
|
aSettings.SetStyleSettings(aStyleSettings);
|
|
|
|
SetSettings(aSettings);
|
|
|
|
}
|
2001-01-09 15:11:54 +00:00
|
|
|
//==============================================================================
|
2010-10-12 15:59:03 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|