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( sal_False )
72 0 : ,m_bStopTimer(sal_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 : if (m_timerUndoActionCreation.IsActive())
109 0 : m_timerUndoActionCreation.Stop();
110 0 : css::uno::Reference< css::beans::XMultiPropertySet > n;
111 : {
112 0 : osl::MutexGuard g(m_mutex);
113 0 : n = m_notifier;
114 : }
115 0 : if (n.is()) {
116 0 : n->removePropertiesChangeListener(m_listener.get());
117 : }
118 0 : m_ColorConfig.RemoveListener(this);
119 0 : }
120 :
121 0 : void OSqlEdit::KeyInput( const KeyEvent& rKEvt )
122 : {
123 0 : OJoinController& rController = m_pView->getContainerWindow()->getDesignView()->getController();
124 0 : rController.InvalidateFeature(SID_CUT);
125 0 : rController.InvalidateFeature(SID_COPY);
126 :
127 : // Is this a cut, copy, paste event?
128 0 : KeyFuncType aKeyFunc = rKEvt.GetKeyCode().GetFunction();
129 0 : if( (aKeyFunc==KEYFUNC_CUT)||(aKeyFunc==KEYFUNC_COPY)||(aKeyFunc==KEYFUNC_PASTE) )
130 0 : m_bAccelAction = sal_True;
131 :
132 0 : MultiLineEditSyntaxHighlight::KeyInput( rKEvt );
133 :
134 0 : if( m_bAccelAction )
135 0 : m_bAccelAction = sal_False;
136 0 : }
137 :
138 0 : sal_Bool OSqlEdit::IsInAccelAct()
139 : {
140 : // Cut, Copy, Paste by Accel. runs the action in the Edit but also the
141 : // corresponding slot in the View. Therefore, the action occurs twice.
142 : // To prevent this, SlotExec in View can call this function.
143 :
144 0 : return m_bAccelAction;
145 : }
146 :
147 0 : void OSqlEdit::GetFocus()
148 : {
149 0 : m_strOrigText =GetText();
150 0 : MultiLineEditSyntaxHighlight::GetFocus();
151 0 : }
152 :
153 0 : IMPL_LINK_NOARG(OSqlEdit, OnUndoActionTimer)
154 : {
155 0 : OUString aText = GetText();
156 0 : if(aText != m_strOrigText)
157 : {
158 0 : OJoinController& rController = m_pView->getContainerWindow()->getDesignView()->getController();
159 0 : SfxUndoManager& rUndoMgr = rController.GetUndoManager();
160 0 : OSqlEditUndoAct* pUndoAct = new OSqlEditUndoAct( this );
161 :
162 0 : pUndoAct->SetOriginalText( m_strOrigText );
163 0 : rUndoMgr.AddUndoAction( pUndoAct );
164 :
165 0 : rController.InvalidateFeature(SID_UNDO);
166 0 : rController.InvalidateFeature(SID_REDO);
167 :
168 0 : m_strOrigText =aText;
169 : }
170 :
171 0 : return 0L;
172 : }
173 :
174 0 : IMPL_LINK_NOARG(OSqlEdit, OnInvalidateTimer)
175 : {
176 0 : OJoinController& rController = m_pView->getContainerWindow()->getDesignView()->getController();
177 0 : rController.InvalidateFeature(SID_CUT);
178 0 : rController.InvalidateFeature(SID_COPY);
179 0 : if(!m_bStopTimer)
180 0 : m_timerInvalidate.Start();
181 0 : return 0L;
182 : }
183 :
184 0 : IMPL_LINK(OSqlEdit, ModifyHdl, void*, /*EMPTYTAG*/)
185 : {
186 0 : if (m_timerUndoActionCreation.IsActive())
187 0 : m_timerUndoActionCreation.Stop();
188 0 : m_timerUndoActionCreation.Start();
189 :
190 0 : OJoinController& rController = m_pView->getContainerWindow()->getDesignView()->getController();
191 0 : if (!rController.isModified())
192 0 : rController.setModified( sal_True );
193 :
194 0 : rController.InvalidateFeature(SID_SBA_QRY_EXECUTE);
195 0 : rController.InvalidateFeature(SID_CUT);
196 0 : rController.InvalidateFeature(SID_COPY);
197 :
198 0 : m_lnkTextModifyHdl.Call(NULL);
199 0 : return 0;
200 : }
201 :
202 0 : void OSqlEdit::SetText(const OUString& rNewText)
203 : {
204 0 : if (m_timerUndoActionCreation.IsActive())
205 : { // create the trailing undo-actions
206 0 : m_timerUndoActionCreation.Stop();
207 0 : LINK(this, OSqlEdit, OnUndoActionTimer).Call(NULL);
208 : }
209 :
210 0 : MultiLineEditSyntaxHighlight::SetText(rNewText);
211 0 : m_strOrigText =rNewText;
212 0 : }
213 :
214 0 : void OSqlEdit::stopTimer()
215 : {
216 0 : m_bStopTimer = sal_True;
217 0 : if (m_timerInvalidate.IsActive())
218 0 : m_timerInvalidate.Stop();
219 0 : }
220 :
221 0 : void OSqlEdit::startTimer()
222 : {
223 0 : m_bStopTimer = sal_False;
224 0 : if (!m_timerInvalidate.IsActive())
225 0 : m_timerInvalidate.Start();
226 0 : }
227 :
228 0 : void OSqlEdit::ConfigurationChanged( utl::ConfigurationBroadcaster* pOption, sal_uInt32 )
229 : {
230 : assert( pOption == &m_ColorConfig );
231 : (void) pOption; // avoid warnings
232 0 : MultiLineEditSyntaxHighlight::UpdateData();
233 0 : }
234 :
235 0 : void OSqlEdit::ImplSetFont()
236 : {
237 0 : AllSettings aSettings = GetSettings();
238 0 : StyleSettings aStyleSettings = aSettings.GetStyleSettings();
239 : OUString sFontName(
240 : officecfg::Office::Common::Font::SourceViewFont::FontName::get().
241 0 : get_value_or( OUString() ) );
242 0 : if ( sFontName.isEmpty() )
243 : {
244 0 : Font aTmpFont( OutputDevice::GetDefaultFont( DEFAULTFONT_FIXED, Application::GetSettings().GetUILanguageTag().getLanguageType(), 0 , this ) );
245 0 : sFontName = aTmpFont.GetName();
246 : }
247 : Size aFontSize(
248 0 : 0, officecfg::Office::Common::Font::SourceViewFont::FontHeight::get() );
249 0 : Font aFont( sFontName, aFontSize );
250 0 : aStyleSettings.SetFieldFont(aFont);
251 0 : aSettings.SetStyleSettings(aStyleSettings);
252 0 : SetSettings(aSettings);
253 0 : }
254 :
255 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|