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: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"
|
2009-10-16 00:05:16 +02:00
|
|
|
#include <svl/smplhint.hxx>
|
2014-01-02 23:52:37 +01:00
|
|
|
#include <vcl/settings.hxx>
|
2008-11-28 11:39:37 +00:00
|
|
|
|
2001-01-09 15:11:54 +00:00
|
|
|
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 &)
|
2014-03-27 18:12:18 +01:00
|
|
|
throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
|
2012-01-25 18:18:18 +01:00
|
|
|
{
|
|
|
|
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 &)
|
2014-03-27 18:12:18 +01:00
|
|
|
throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
|
2012-01-25 18:18:18 +01:00
|
|
|
{
|
|
|
|
SolarMutexGuard g;
|
|
|
|
editor_.ImplSetFont();
|
|
|
|
}
|
|
|
|
|
|
|
|
OSqlEdit & editor_;
|
|
|
|
};
|
|
|
|
|
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)
|
2014-04-17 11:16:55 +02:00
|
|
|
,m_bAccelAction( false )
|
|
|
|
,m_bStopTimer(false )
|
2001-01-09 15:11:54 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2013-04-07 12:06:47 +02:00
|
|
|
css::uno::Sequence< OUString > s(2);
|
2013-11-04 13:33:17 +02:00
|
|
|
s[0] = "FontHeight";
|
|
|
|
s[1] = "FontName";
|
2012-01-25 18:18:18 +01:00
|
|
|
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#
|
2014-02-21 12:53:51 +01:00
|
|
|
EnableFocusSelectionHide( false );
|
2001-01-09 15:11:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
OSqlEdit::~OSqlEdit()
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
2012-08-10 20:50:33 +02:00
|
|
|
|
2001-01-09 15:11:54 +00:00
|
|
|
void OSqlEdit::KeyInput( const KeyEvent& rKEvt )
|
|
|
|
{
|
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
|
|
|
|
2012-08-09 18:25:53 +02:00
|
|
|
// Is this a cut, copy, paste event?
|
2001-01-09 15:11:54 +00:00
|
|
|
KeyFuncType aKeyFunc = rKEvt.GetKeyCode().GetFunction();
|
2014-10-26 13:01:46 +02:00
|
|
|
if( (aKeyFunc==KeyFuncType::CUT)||(aKeyFunc==KeyFuncType::COPY)||(aKeyFunc==KeyFuncType::PASTE) )
|
2014-04-17 11:16:55 +02:00
|
|
|
m_bAccelAction = true;
|
2001-01-09 15:11:54 +00:00
|
|
|
|
2008-11-28 11:39:37 +00:00
|
|
|
MultiLineEditSyntaxHighlight::KeyInput( rKEvt );
|
2001-01-09 15:11:54 +00:00
|
|
|
|
|
|
|
if( m_bAccelAction )
|
2014-04-17 11:16:55 +02:00
|
|
|
m_bAccelAction = false;
|
2001-01-09 15:11:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void OSqlEdit::GetFocus()
|
|
|
|
{
|
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
|
|
|
{
|
2013-09-26 12:17:53 +02:00
|
|
|
OUString 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-08-10 20:50:33 +02:00
|
|
|
|
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;
|
|
|
|
}
|
2012-08-10 20:50:33 +02:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-01-21 14:32:09 +01:00
|
|
|
void OSqlEdit::SetText(const OUString& rNewText)
|
2001-01-09 15:11:54 +00:00
|
|
|
{
|
|
|
|
if (m_timerUndoActionCreation.IsActive())
|
2012-08-09 18:25:53 +02:00
|
|
|
{ // create the trailing undo-actions
|
2001-01-09 15:11:54 +00:00
|
|
|
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
|
|
|
}
|
2012-08-10 20:50:33 +02:00
|
|
|
|
2001-04-18 12:20:48 +00:00
|
|
|
void OSqlEdit::stopTimer()
|
|
|
|
{
|
2014-04-17 11:16:55 +02:00
|
|
|
m_bStopTimer = true;
|
2001-04-18 12:20:48 +00:00
|
|
|
if (m_timerInvalidate.IsActive())
|
|
|
|
m_timerInvalidate.Stop();
|
|
|
|
}
|
2012-08-10 20:50:33 +02:00
|
|
|
|
2001-04-18 12:20:48 +00:00
|
|
|
void OSqlEdit::startTimer()
|
|
|
|
{
|
2014-04-17 11:16:55 +02:00
|
|
|
m_bStopTimer = false;
|
2001-04-18 12:20:48 +00:00
|
|
|
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();
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sFontName(
|
2012-01-31 17:25:42 +01:00
|
|
|
officecfg::Office::Common::Font::SourceViewFont::FontName::get().
|
2013-04-07 12:06:47 +02:00
|
|
|
get_value_or( OUString() ) );
|
2012-01-25 18:18:18 +01:00
|
|
|
if ( sFontName.isEmpty() )
|
2008-11-28 11:39:37 +00:00
|
|
|
{
|
2014-09-16 10:09:58 +02:00
|
|
|
vcl::Font aTmpFont( OutputDevice::GetDefaultFont( DEFAULTFONT_FIXED, Application::GetSettings().GetUILanguageTag().getLanguageType(), 0 , this ) );
|
2008-11-28 11:39:37 +00:00
|
|
|
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() );
|
2014-09-16 10:09:58 +02:00
|
|
|
vcl::Font aFont( sFontName, aFontSize );
|
2008-11-28 11:39:37 +00:00
|
|
|
aStyleSettings.SetFieldFont(aFont);
|
|
|
|
aSettings.SetStyleSettings(aStyleSettings);
|
|
|
|
SetSettings(aSettings);
|
|
|
|
}
|
2010-10-12 15:59:03 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|