Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "sal/config.h"
21 :
22 : #include <cassert>
23 :
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 :
39 : using namespace dbaui;
40 :
41 : class OSqlEdit::ChangesListener:
42 : public cppu::WeakImplHelper1< css::beans::XPropertiesChangeListener >
43 : {
44 : public:
45 0 : ChangesListener(OSqlEdit & editor): editor_(editor) {}
46 :
47 : private:
48 0 : virtual ~ChangesListener() {}
49 :
50 0 : virtual void SAL_CALL disposing(css::lang::EventObject const &)
51 : throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
52 : {
53 0 : osl::MutexGuard g(editor_.m_mutex);
54 0 : editor_.m_notifier.clear();
55 0 : }
56 :
57 0 : virtual void SAL_CALL propertiesChange(
58 : css::uno::Sequence< css::beans::PropertyChangeEvent > const &)
59 : throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
60 : {
61 0 : SolarMutexGuard g;
62 0 : editor_.ImplSetFont();
63 0 : }
64 :
65 : OSqlEdit & editor_;
66 : };
67 :
68 0 : OSqlEdit::OSqlEdit( OQueryTextView* pParent, WinBits nWinStyle ) :
69 : MultiLineEditSyntaxHighlight( pParent, nWinStyle )
70 : ,m_pView(pParent)
71 : ,m_bAccelAction( false )
72 0 : ,m_bStopTimer(false )
73 : {
74 0 : SetHelpId( HID_CTL_QRYSQLEDIT );
75 0 : SetModifyHdl( LINK(this, OSqlEdit, ModifyHdl) );
76 :
77 0 : m_timerUndoActionCreation.SetTimeout(1000);
78 0 : m_timerUndoActionCreation.SetTimeoutHdl(LINK(this, OSqlEdit, OnUndoActionTimer));
79 :
80 0 : m_timerInvalidate.SetTimeout(200);
81 0 : m_timerInvalidate.SetTimeoutHdl(LINK(this, OSqlEdit, OnInvalidateTimer));
82 0 : m_timerInvalidate.Start();
83 :
84 0 : 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 0 : m_listener = new ChangesListener(*this);
89 : css::uno::Reference< css::beans::XMultiPropertySet > n(
90 : officecfg::Office::Common::Font::SourceViewFont::get(),
91 0 : css::uno::UNO_QUERY_THROW);
92 : {
93 0 : osl::MutexGuard g(m_mutex);
94 0 : m_notifier = n;
95 : }
96 0 : css::uno::Sequence< OUString > s(2);
97 0 : s[0] = "FontHeight";
98 0 : s[1] = "FontName";
99 0 : n->addPropertiesChangeListener(s, m_listener.get());
100 0 : m_ColorConfig.AddListener(this);
101 :
102 : //#i97044#
103 0 : EnableFocusSelectionHide( false );
104 0 : }
105 :
106 0 : OSqlEdit::~OSqlEdit()
107 : {
108 0 : disposeOnce();
109 0 : }
110 :
111 0 : void OSqlEdit::dispose()
112 : {
113 0 : if (m_timerUndoActionCreation.IsActive())
114 0 : m_timerUndoActionCreation.Stop();
115 0 : css::uno::Reference< css::beans::XMultiPropertySet > n;
116 : {
117 0 : osl::MutexGuard g(m_mutex);
118 0 : n = m_notifier;
119 : }
120 0 : if (n.is()) {
121 0 : n->removePropertiesChangeListener(m_listener.get());
122 : }
123 0 : m_ColorConfig.RemoveListener(this);
124 0 : m_pView.clear();
125 0 : MultiLineEditSyntaxHighlight::dispose();
126 0 : }
127 :
128 0 : void OSqlEdit::KeyInput( const KeyEvent& rKEvt )
129 : {
130 0 : OJoinController& rController = m_pView->getContainerWindow()->getDesignView()->getController();
131 0 : rController.InvalidateFeature(SID_CUT);
132 0 : rController.InvalidateFeature(SID_COPY);
133 :
134 : // Is this a cut, copy, paste event?
135 0 : KeyFuncType aKeyFunc = rKEvt.GetKeyCode().GetFunction();
136 0 : if( (aKeyFunc==KeyFuncType::CUT)||(aKeyFunc==KeyFuncType::COPY)||(aKeyFunc==KeyFuncType::PASTE) )
137 0 : m_bAccelAction = true;
138 :
139 0 : MultiLineEditSyntaxHighlight::KeyInput( rKEvt );
140 :
141 0 : if( m_bAccelAction )
142 0 : m_bAccelAction = false;
143 0 : }
144 :
145 :
146 0 : void OSqlEdit::GetFocus()
147 : {
148 0 : m_strOrigText =GetText();
149 0 : MultiLineEditSyntaxHighlight::GetFocus();
150 0 : }
151 :
152 0 : IMPL_LINK_NOARG_TYPED(OSqlEdit, OnUndoActionTimer, Timer *, void)
153 : {
154 0 : OUString aText = GetText();
155 0 : if(aText != m_strOrigText)
156 : {
157 0 : OJoinController& rController = m_pView->getContainerWindow()->getDesignView()->getController();
158 0 : SfxUndoManager& rUndoMgr = rController.GetUndoManager();
159 0 : OSqlEditUndoAct* pUndoAct = new OSqlEditUndoAct( this );
160 :
161 0 : pUndoAct->SetOriginalText( m_strOrigText );
162 0 : rUndoMgr.AddUndoAction( pUndoAct );
163 :
164 0 : rController.InvalidateFeature(SID_UNDO);
165 0 : rController.InvalidateFeature(SID_REDO);
166 :
167 0 : m_strOrigText =aText;
168 0 : }
169 0 : }
170 :
171 0 : IMPL_LINK_NOARG_TYPED(OSqlEdit, OnInvalidateTimer, Timer *, void)
172 : {
173 0 : OJoinController& rController = m_pView->getContainerWindow()->getDesignView()->getController();
174 0 : rController.InvalidateFeature(SID_CUT);
175 0 : rController.InvalidateFeature(SID_COPY);
176 0 : if(!m_bStopTimer)
177 0 : m_timerInvalidate.Start();
178 0 : }
179 :
180 0 : IMPL_LINK_NOARG(OSqlEdit, ModifyHdl)
181 : {
182 0 : if (m_timerUndoActionCreation.IsActive())
183 0 : m_timerUndoActionCreation.Stop();
184 0 : m_timerUndoActionCreation.Start();
185 :
186 0 : OJoinController& rController = m_pView->getContainerWindow()->getDesignView()->getController();
187 0 : if (!rController.isModified())
188 0 : rController.setModified( sal_True );
189 :
190 0 : rController.InvalidateFeature(SID_SBA_QRY_EXECUTE);
191 0 : rController.InvalidateFeature(SID_CUT);
192 0 : rController.InvalidateFeature(SID_COPY);
193 :
194 0 : m_lnkTextModifyHdl.Call(NULL);
195 0 : return 0;
196 : }
197 :
198 0 : void OSqlEdit::SetText(const OUString& rNewText)
199 : {
200 0 : if (m_timerUndoActionCreation.IsActive())
201 : { // create the trailing undo-actions
202 0 : m_timerUndoActionCreation.Stop();
203 0 : LINK(this, OSqlEdit, OnUndoActionTimer).Call(NULL);
204 : }
205 :
206 0 : MultiLineEditSyntaxHighlight::SetText(rNewText);
207 0 : m_strOrigText =rNewText;
208 0 : }
209 :
210 0 : void OSqlEdit::stopTimer()
211 : {
212 0 : m_bStopTimer = true;
213 0 : if (m_timerInvalidate.IsActive())
214 0 : m_timerInvalidate.Stop();
215 0 : }
216 :
217 0 : void OSqlEdit::startTimer()
218 : {
219 0 : m_bStopTimer = false;
220 0 : if (!m_timerInvalidate.IsActive())
221 0 : m_timerInvalidate.Start();
222 0 : }
223 :
224 0 : void OSqlEdit::ConfigurationChanged( utl::ConfigurationBroadcaster* pOption, sal_uInt32 )
225 : {
226 : assert( pOption == &m_ColorConfig );
227 : (void) pOption; // avoid warnings
228 0 : MultiLineEditSyntaxHighlight::UpdateData();
229 0 : }
230 :
231 0 : void OSqlEdit::ImplSetFont()
232 : {
233 0 : AllSettings aSettings = GetSettings();
234 0 : StyleSettings aStyleSettings = aSettings.GetStyleSettings();
235 : OUString sFontName(
236 : officecfg::Office::Common::Font::SourceViewFont::FontName::get().
237 0 : get_value_or( OUString() ) );
238 0 : if ( sFontName.isEmpty() )
239 : {
240 0 : vcl::Font aTmpFont( OutputDevice::GetDefaultFont( DefaultFontType::FIXED, Application::GetSettings().GetUILanguageTag().getLanguageType(), GetDefaultFontFlags::NONE, this ) );
241 0 : sFontName = aTmpFont.GetName();
242 : }
243 : Size aFontSize(
244 0 : 0, officecfg::Office::Common::Font::SourceViewFont::FontHeight::get() );
245 0 : vcl::Font aFont( sFontName, aFontSize );
246 0 : aStyleSettings.SetFieldFont(aFont);
247 0 : aSettings.SetStyleSettings(aStyleSettings);
248 0 : SetSettings(aSettings);
249 36 : }
250 :
251 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|