1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "sal/config.h"
24 #include "com/sun/star/beans/XMultiPropertySet.hpp"
25 #include "com/sun/star/beans/XPropertiesChangeListener.hpp"
26 #include "officecfg/Office/Common.hxx"
27 #include "sqledit.hxx"
28 #include "QueryTextView.hxx"
29 #include "querycontainerwindow.hxx"
30 #include <tools/debug.hxx>
31 #include "dbaccess_helpid.hrc"
32 #include "browserids.hxx"
33 #include "querycontroller.hxx"
34 #include "undosqledit.hxx"
35 #include "QueryDesignView.hxx"
36 #include <svl/smplhint.hxx>
37 #include <vcl/settings.hxx>
38 #include <cppuhelper/implbase.hxx>
40 using namespace dbaui
;
42 class OSqlEdit::ChangesListener
:
43 public cppu::WeakImplHelper
< css::beans::XPropertiesChangeListener
>
46 explicit ChangesListener(OSqlEdit
& editor
): editor_(editor
) {}
49 virtual ~ChangesListener() {}
51 virtual void SAL_CALL
disposing(css::lang::EventObject
const &)
52 throw (css::uno::RuntimeException
, std::exception
) override
54 osl::MutexGuard
g(editor_
.m_mutex
);
55 editor_
.m_notifier
.clear();
58 virtual void SAL_CALL
propertiesChange(
59 css::uno::Sequence
< css::beans::PropertyChangeEvent
> const &)
60 throw (css::uno::RuntimeException
, std::exception
) override
63 editor_
.ImplSetFont();
69 OSqlEdit::OSqlEdit( OQueryTextView
* pParent
, WinBits nWinStyle
) :
70 MultiLineEditSyntaxHighlight( pParent
, nWinStyle
)
72 ,m_bAccelAction( false )
75 SetHelpId( HID_CTL_QRYSQLEDIT
);
76 SetModifyHdl( LINK(this, OSqlEdit
, ModifyHdl
) );
78 m_timerUndoActionCreation
.SetTimeout(1000);
79 m_timerUndoActionCreation
.SetTimeoutHdl(LINK(this, OSqlEdit
, OnUndoActionTimer
));
81 m_timerInvalidate
.SetTimeout(200);
82 m_timerInvalidate
.SetTimeoutHdl(LINK(this, OSqlEdit
, OnInvalidateTimer
));
83 m_timerInvalidate
.Start();
86 // Listen for change of Font and Color Settings:
87 // Using "this" in ctor is a little fishy, but should work here at least as
88 // long as there are no derivations:
89 m_listener
= new ChangesListener(*this);
90 css::uno::Reference
< css::beans::XMultiPropertySet
> n(
91 officecfg::Office::Common::Font::SourceViewFont::get(),
92 css::uno::UNO_QUERY_THROW
);
94 osl::MutexGuard
g(m_mutex
);
97 css::uno::Sequence
< OUString
> s(2);
100 n
->addPropertiesChangeListener(s
, m_listener
.get());
101 m_ColorConfig
.AddListener(this);
104 EnableFocusSelectionHide( false );
107 OSqlEdit::~OSqlEdit()
112 void OSqlEdit::dispose()
114 if (m_timerUndoActionCreation
.IsActive())
115 m_timerUndoActionCreation
.Stop();
116 css::uno::Reference
< css::beans::XMultiPropertySet
> n
;
118 osl::MutexGuard
g(m_mutex
);
122 n
->removePropertiesChangeListener(m_listener
.get());
124 m_ColorConfig
.RemoveListener(this);
126 MultiLineEditSyntaxHighlight::dispose();
129 void OSqlEdit::KeyInput( const KeyEvent
& rKEvt
)
131 OJoinController
& rController
= m_pView
->getContainerWindow()->getDesignView()->getController();
132 rController
.InvalidateFeature(SID_CUT
);
133 rController
.InvalidateFeature(SID_COPY
);
135 // Is this a cut, copy, paste event?
136 KeyFuncType aKeyFunc
= rKEvt
.GetKeyCode().GetFunction();
137 if( (aKeyFunc
==KeyFuncType::CUT
)||(aKeyFunc
==KeyFuncType::COPY
)||(aKeyFunc
==KeyFuncType::PASTE
) )
138 m_bAccelAction
= true;
140 MultiLineEditSyntaxHighlight::KeyInput( rKEvt
);
143 m_bAccelAction
= false;
147 void OSqlEdit::GetFocus()
149 m_strOrigText
=GetText();
150 MultiLineEditSyntaxHighlight::GetFocus();
153 IMPL_LINK_NOARG_TYPED(OSqlEdit
, OnUndoActionTimer
, Timer
*, void)
155 OUString aText
= GetText();
156 if(aText
!= m_strOrigText
)
158 OJoinController
& rController
= m_pView
->getContainerWindow()->getDesignView()->getController();
159 SfxUndoManager
& rUndoMgr
= rController
.GetUndoManager();
160 OSqlEditUndoAct
* pUndoAct
= new OSqlEditUndoAct( this );
162 pUndoAct
->SetOriginalText( m_strOrigText
);
163 rUndoMgr
.AddUndoAction( pUndoAct
);
165 rController
.InvalidateFeature(SID_UNDO
);
166 rController
.InvalidateFeature(SID_REDO
);
168 m_strOrigText
=aText
;
172 IMPL_LINK_NOARG_TYPED(OSqlEdit
, OnInvalidateTimer
, Timer
*, void)
174 OJoinController
& rController
= m_pView
->getContainerWindow()->getDesignView()->getController();
175 rController
.InvalidateFeature(SID_CUT
);
176 rController
.InvalidateFeature(SID_COPY
);
178 m_timerInvalidate
.Start();
181 IMPL_LINK_NOARG_TYPED(OSqlEdit
, ModifyHdl
, Edit
&, void)
183 if (m_timerUndoActionCreation
.IsActive())
184 m_timerUndoActionCreation
.Stop();
185 m_timerUndoActionCreation
.Start();
187 OJoinController
& rController
= m_pView
->getContainerWindow()->getDesignView()->getController();
188 if (!rController
.isModified())
189 rController
.setModified( true );
191 rController
.InvalidateFeature(SID_SBA_QRY_EXECUTE
);
192 rController
.InvalidateFeature(SID_CUT
);
193 rController
.InvalidateFeature(SID_COPY
);
196 void OSqlEdit::SetText(const OUString
& rNewText
)
198 if (m_timerUndoActionCreation
.IsActive())
199 { // create the trailing undo-actions
200 m_timerUndoActionCreation
.Stop();
201 LINK(this, OSqlEdit
, OnUndoActionTimer
).Call(nullptr);
204 MultiLineEditSyntaxHighlight::SetText(rNewText
);
205 m_strOrigText
=rNewText
;
208 void OSqlEdit::stopTimer()
211 if (m_timerInvalidate
.IsActive())
212 m_timerInvalidate
.Stop();
215 void OSqlEdit::startTimer()
217 m_bStopTimer
= false;
218 if (!m_timerInvalidate
.IsActive())
219 m_timerInvalidate
.Start();
222 void OSqlEdit::ConfigurationChanged( utl::ConfigurationBroadcaster
* pOption
, sal_uInt32
)
224 assert( pOption
== &m_ColorConfig
);
225 (void) pOption
; // avoid warnings
226 MultiLineEditSyntaxHighlight::UpdateData();
229 void OSqlEdit::ImplSetFont()
231 AllSettings aSettings
= GetSettings();
232 StyleSettings aStyleSettings
= aSettings
.GetStyleSettings();
234 officecfg::Office::Common::Font::SourceViewFont::FontName::get().
235 get_value_or( OUString() ) );
236 if ( sFontName
.isEmpty() )
238 vcl::Font
aTmpFont( OutputDevice::GetDefaultFont( DefaultFontType::FIXED
, Application::GetSettings().GetUILanguageTag().getLanguageType(), GetDefaultFontFlags::NONE
, this ) );
239 sFontName
= aTmpFont
.GetFamilyName();
242 0, officecfg::Office::Common::Font::SourceViewFont::FontHeight::get() );
243 vcl::Font
aFont( sFontName
, aFontSize
);
244 aStyleSettings
.SetFieldFont(aFont
);
245 aSettings
.SetStyleSettings(aStyleSettings
);
246 SetSettings(aSettings
);
249 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */