Bump version to 5.0-14
[LibreOffice.git] / dbaccess / source / ui / control / sqledit.cxx
blob938404686cc463bc9ed98b8c187d48dc885fd4cf
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
22 #include <cassert>
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>
39 using namespace dbaui;
41 class OSqlEdit::ChangesListener:
42 public cppu::WeakImplHelper1< css::beans::XPropertiesChangeListener >
44 public:
45 ChangesListener(OSqlEdit & editor): editor_(editor) {}
47 private:
48 virtual ~ChangesListener() {}
50 virtual void SAL_CALL disposing(css::lang::EventObject const &)
51 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
53 osl::MutexGuard g(editor_.m_mutex);
54 editor_.m_notifier.clear();
57 virtual void SAL_CALL propertiesChange(
58 css::uno::Sequence< css::beans::PropertyChangeEvent > const &)
59 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
61 SolarMutexGuard g;
62 editor_.ImplSetFont();
65 OSqlEdit & editor_;
68 OSqlEdit::OSqlEdit( OQueryTextView* pParent, WinBits nWinStyle ) :
69 MultiLineEditSyntaxHighlight( pParent, nWinStyle )
70 ,m_pView(pParent)
71 ,m_bAccelAction( false )
72 ,m_bStopTimer(false )
74 SetHelpId( HID_CTL_QRYSQLEDIT );
75 SetModifyHdl( LINK(this, OSqlEdit, ModifyHdl) );
77 m_timerUndoActionCreation.SetTimeout(1000);
78 m_timerUndoActionCreation.SetTimeoutHdl(LINK(this, OSqlEdit, OnUndoActionTimer));
80 m_timerInvalidate.SetTimeout(200);
81 m_timerInvalidate.SetTimeoutHdl(LINK(this, OSqlEdit, OnInvalidateTimer));
82 m_timerInvalidate.Start();
84 ImplSetFont();
85 // Listen for change of Font and Color Settings:
86 // Using "this" in ctor is a little fishy, but should work here at least as
87 // long as there are no derivations:
88 m_listener = new ChangesListener(*this);
89 css::uno::Reference< css::beans::XMultiPropertySet > n(
90 officecfg::Office::Common::Font::SourceViewFont::get(),
91 css::uno::UNO_QUERY_THROW);
93 osl::MutexGuard g(m_mutex);
94 m_notifier = n;
96 css::uno::Sequence< OUString > s(2);
97 s[0] = "FontHeight";
98 s[1] = "FontName";
99 n->addPropertiesChangeListener(s, m_listener.get());
100 m_ColorConfig.AddListener(this);
102 //#i97044#
103 EnableFocusSelectionHide( false );
106 OSqlEdit::~OSqlEdit()
108 disposeOnce();
111 void OSqlEdit::dispose()
113 if (m_timerUndoActionCreation.IsActive())
114 m_timerUndoActionCreation.Stop();
115 css::uno::Reference< css::beans::XMultiPropertySet > n;
117 osl::MutexGuard g(m_mutex);
118 n = m_notifier;
120 if (n.is()) {
121 n->removePropertiesChangeListener(m_listener.get());
123 m_ColorConfig.RemoveListener(this);
124 m_pView.clear();
125 MultiLineEditSyntaxHighlight::dispose();
128 void OSqlEdit::KeyInput( const KeyEvent& rKEvt )
130 OJoinController& rController = m_pView->getContainerWindow()->getDesignView()->getController();
131 rController.InvalidateFeature(SID_CUT);
132 rController.InvalidateFeature(SID_COPY);
134 // Is this a cut, copy, paste event?
135 KeyFuncType aKeyFunc = rKEvt.GetKeyCode().GetFunction();
136 if( (aKeyFunc==KeyFuncType::CUT)||(aKeyFunc==KeyFuncType::COPY)||(aKeyFunc==KeyFuncType::PASTE) )
137 m_bAccelAction = true;
139 MultiLineEditSyntaxHighlight::KeyInput( rKEvt );
141 if( m_bAccelAction )
142 m_bAccelAction = false;
146 void OSqlEdit::GetFocus()
148 m_strOrigText =GetText();
149 MultiLineEditSyntaxHighlight::GetFocus();
152 IMPL_LINK_NOARG_TYPED(OSqlEdit, OnUndoActionTimer, Timer *, void)
154 OUString aText = GetText();
155 if(aText != m_strOrigText)
157 OJoinController& rController = m_pView->getContainerWindow()->getDesignView()->getController();
158 SfxUndoManager& rUndoMgr = rController.GetUndoManager();
159 OSqlEditUndoAct* pUndoAct = new OSqlEditUndoAct( this );
161 pUndoAct->SetOriginalText( m_strOrigText );
162 rUndoMgr.AddUndoAction( pUndoAct );
164 rController.InvalidateFeature(SID_UNDO);
165 rController.InvalidateFeature(SID_REDO);
167 m_strOrigText =aText;
171 IMPL_LINK_NOARG_TYPED(OSqlEdit, OnInvalidateTimer, Timer *, void)
173 OJoinController& rController = m_pView->getContainerWindow()->getDesignView()->getController();
174 rController.InvalidateFeature(SID_CUT);
175 rController.InvalidateFeature(SID_COPY);
176 if(!m_bStopTimer)
177 m_timerInvalidate.Start();
180 IMPL_LINK_NOARG(OSqlEdit, ModifyHdl)
182 if (m_timerUndoActionCreation.IsActive())
183 m_timerUndoActionCreation.Stop();
184 m_timerUndoActionCreation.Start();
186 OJoinController& rController = m_pView->getContainerWindow()->getDesignView()->getController();
187 if (!rController.isModified())
188 rController.setModified( sal_True );
190 rController.InvalidateFeature(SID_SBA_QRY_EXECUTE);
191 rController.InvalidateFeature(SID_CUT);
192 rController.InvalidateFeature(SID_COPY);
194 m_lnkTextModifyHdl.Call(NULL);
195 return 0;
198 void OSqlEdit::SetText(const OUString& rNewText)
200 if (m_timerUndoActionCreation.IsActive())
201 { // create the trailing undo-actions
202 m_timerUndoActionCreation.Stop();
203 LINK(this, OSqlEdit, OnUndoActionTimer).Call(NULL);
206 MultiLineEditSyntaxHighlight::SetText(rNewText);
207 m_strOrigText =rNewText;
210 void OSqlEdit::stopTimer()
212 m_bStopTimer = true;
213 if (m_timerInvalidate.IsActive())
214 m_timerInvalidate.Stop();
217 void OSqlEdit::startTimer()
219 m_bStopTimer = false;
220 if (!m_timerInvalidate.IsActive())
221 m_timerInvalidate.Start();
224 void OSqlEdit::ConfigurationChanged( utl::ConfigurationBroadcaster* pOption, sal_uInt32 )
226 assert( pOption == &m_ColorConfig );
227 (void) pOption; // avoid warnings
228 MultiLineEditSyntaxHighlight::UpdateData();
231 void OSqlEdit::ImplSetFont()
233 AllSettings aSettings = GetSettings();
234 StyleSettings aStyleSettings = aSettings.GetStyleSettings();
235 OUString sFontName(
236 officecfg::Office::Common::Font::SourceViewFont::FontName::get().
237 get_value_or( OUString() ) );
238 if ( sFontName.isEmpty() )
240 vcl::Font aTmpFont( OutputDevice::GetDefaultFont( DefaultFontType::FIXED, Application::GetSettings().GetUILanguageTag().getLanguageType(), GetDefaultFontFlags::NONE, this ) );
241 sFontName = aTmpFont.GetName();
243 Size aFontSize(
244 0, officecfg::Office::Common::Font::SourceViewFont::FontHeight::get() );
245 vcl::Font aFont( sFontName, aFontSize );
246 aStyleSettings.SetFieldFont(aFont);
247 aSettings.SetStyleSettings(aStyleSettings);
248 SetSettings(aSettings);
251 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */