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 :
38 : using namespace dbaui;
39 :
40 : class OSqlEdit::ChangesListener:
41 : public cppu::WeakImplHelper1< css::beans::XPropertiesChangeListener >
42 : {
43 : public:
44 0 : ChangesListener(OSqlEdit & editor): editor_(editor) {}
45 :
46 : private:
47 0 : virtual ~ChangesListener() {}
48 :
49 0 : virtual void SAL_CALL disposing(css::lang::EventObject const &)
50 : throw (css::uno::RuntimeException)
51 : {
52 0 : osl::MutexGuard g(editor_.m_mutex);
53 0 : editor_.m_notifier.clear();
54 0 : }
55 :
56 0 : virtual void SAL_CALL propertiesChange(
57 : css::uno::Sequence< css::beans::PropertyChangeEvent > const &)
58 : throw (css::uno::RuntimeException)
59 : {
60 0 : SolarMutexGuard g;
61 0 : editor_.ImplSetFont();
62 0 : }
63 :
64 : OSqlEdit & editor_;
65 : };
66 :
67 : DBG_NAME(OSqlEdit)
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 : DBG_CTOR(OSqlEdit,NULL);
75 0 : SetHelpId( HID_CTL_QRYSQLEDIT );
76 0 : SetModifyHdl( LINK(this, OSqlEdit, ModifyHdl) );
77 :
78 0 : m_timerUndoActionCreation.SetTimeout(1000);
79 0 : m_timerUndoActionCreation.SetTimeoutHdl(LINK(this, OSqlEdit, OnUndoActionTimer));
80 :
81 0 : m_timerInvalidate.SetTimeout(200);
82 0 : m_timerInvalidate.SetTimeoutHdl(LINK(this, OSqlEdit, OnInvalidateTimer));
83 0 : m_timerInvalidate.Start();
84 :
85 0 : ImplSetFont();
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 0 : m_listener = new ChangesListener(*this);
90 : css::uno::Reference< css::beans::XMultiPropertySet > n(
91 : officecfg::Office::Common::Font::SourceViewFont::get(),
92 0 : css::uno::UNO_QUERY_THROW);
93 : {
94 0 : osl::MutexGuard g(m_mutex);
95 0 : m_notifier = n;
96 : }
97 0 : css::uno::Sequence< rtl::OUString > s(2);
98 0 : s[0] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FontHeight"));
99 0 : s[1] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FontName"));
100 0 : n->addPropertiesChangeListener(s, m_listener.get());
101 0 : m_ColorConfig.AddListener(this);
102 :
103 : //#i97044#
104 0 : EnableFocusSelectionHide( sal_False );
105 0 : }
106 :
107 0 : OSqlEdit::~OSqlEdit()
108 : {
109 : DBG_DTOR(OSqlEdit,NULL);
110 0 : if (m_timerUndoActionCreation.IsActive())
111 0 : m_timerUndoActionCreation.Stop();
112 0 : css::uno::Reference< css::beans::XMultiPropertySet > n;
113 : {
114 0 : osl::MutexGuard g(m_mutex);
115 0 : n = m_notifier;
116 : }
117 0 : if (n.is()) {
118 0 : n->removePropertiesChangeListener(m_listener.get());
119 : }
120 0 : m_ColorConfig.RemoveListener(this);
121 0 : }
122 :
123 0 : void OSqlEdit::KeyInput( const KeyEvent& rKEvt )
124 : {
125 : DBG_CHKTHIS(OSqlEdit,NULL);
126 0 : OJoinController& rController = m_pView->getContainerWindow()->getDesignView()->getController();
127 0 : rController.InvalidateFeature(SID_CUT);
128 0 : rController.InvalidateFeature(SID_COPY);
129 :
130 : // Is this a cut, copy, paste event?
131 0 : KeyFuncType aKeyFunc = rKEvt.GetKeyCode().GetFunction();
132 0 : if( (aKeyFunc==KEYFUNC_CUT)||(aKeyFunc==KEYFUNC_COPY)||(aKeyFunc==KEYFUNC_PASTE) )
133 0 : m_bAccelAction = sal_True;
134 :
135 0 : MultiLineEditSyntaxHighlight::KeyInput( rKEvt );
136 :
137 0 : if( m_bAccelAction )
138 0 : m_bAccelAction = sal_False;
139 0 : }
140 :
141 0 : sal_Bool OSqlEdit::IsInAccelAct()
142 : {
143 : DBG_CHKTHIS(OSqlEdit,NULL);
144 : // Cut, Copy, Paste by Accel. runs the action in the Edit but also the
145 : // corresponding slot in the View. Therefore, the action occurs twice.
146 : // To prevent this, SlotExec in View can call this function.
147 :
148 0 : return m_bAccelAction;
149 : }
150 :
151 0 : void OSqlEdit::GetFocus()
152 : {
153 : DBG_CHKTHIS(OSqlEdit,NULL);
154 0 : m_strOrigText =GetText();
155 0 : MultiLineEditSyntaxHighlight::GetFocus();
156 0 : }
157 :
158 0 : IMPL_LINK_NOARG(OSqlEdit, OnUndoActionTimer)
159 : {
160 0 : String aText =GetText();
161 0 : if(aText != m_strOrigText)
162 : {
163 0 : OJoinController& rController = m_pView->getContainerWindow()->getDesignView()->getController();
164 0 : SfxUndoManager& rUndoMgr = rController.GetUndoManager();
165 0 : OSqlEditUndoAct* pUndoAct = new OSqlEditUndoAct( this );
166 :
167 0 : pUndoAct->SetOriginalText( m_strOrigText );
168 0 : rUndoMgr.AddUndoAction( pUndoAct );
169 :
170 0 : rController.InvalidateFeature(SID_UNDO);
171 0 : rController.InvalidateFeature(SID_REDO);
172 :
173 0 : m_strOrigText =aText;
174 : }
175 :
176 0 : return 0L;
177 : }
178 :
179 0 : IMPL_LINK_NOARG(OSqlEdit, OnInvalidateTimer)
180 : {
181 0 : OJoinController& rController = m_pView->getContainerWindow()->getDesignView()->getController();
182 0 : rController.InvalidateFeature(SID_CUT);
183 0 : rController.InvalidateFeature(SID_COPY);
184 0 : if(!m_bStopTimer)
185 0 : m_timerInvalidate.Start();
186 0 : return 0L;
187 : }
188 :
189 0 : IMPL_LINK(OSqlEdit, ModifyHdl, void*, /*EMPTYTAG*/)
190 : {
191 0 : if (m_timerUndoActionCreation.IsActive())
192 0 : m_timerUndoActionCreation.Stop();
193 0 : m_timerUndoActionCreation.Start();
194 :
195 0 : OJoinController& rController = m_pView->getContainerWindow()->getDesignView()->getController();
196 0 : if (!rController.isModified())
197 0 : rController.setModified( sal_True );
198 :
199 0 : rController.InvalidateFeature(SID_SBA_QRY_EXECUTE);
200 0 : rController.InvalidateFeature(SID_CUT);
201 0 : rController.InvalidateFeature(SID_COPY);
202 :
203 0 : m_lnkTextModifyHdl.Call(NULL);
204 0 : return 0;
205 : }
206 :
207 0 : void OSqlEdit::SetText(const String& rNewText)
208 : {
209 : DBG_CHKTHIS(OSqlEdit,NULL);
210 0 : if (m_timerUndoActionCreation.IsActive())
211 : { // create the trailing undo-actions
212 0 : m_timerUndoActionCreation.Stop();
213 0 : LINK(this, OSqlEdit, OnUndoActionTimer).Call(NULL);
214 : }
215 :
216 0 : MultiLineEditSyntaxHighlight::SetText(rNewText);
217 0 : m_strOrigText =rNewText;
218 0 : }
219 :
220 0 : void OSqlEdit::stopTimer()
221 : {
222 0 : m_bStopTimer = sal_True;
223 0 : if (m_timerInvalidate.IsActive())
224 0 : m_timerInvalidate.Stop();
225 0 : }
226 :
227 0 : void OSqlEdit::startTimer()
228 : {
229 0 : m_bStopTimer = sal_False;
230 0 : if (!m_timerInvalidate.IsActive())
231 0 : m_timerInvalidate.Start();
232 0 : }
233 :
234 0 : void OSqlEdit::ConfigurationChanged( utl::ConfigurationBroadcaster* pOption, sal_uInt32 )
235 : {
236 : assert( pOption == &m_ColorConfig );
237 : (void) pOption; // avoid warnings
238 0 : MultiLineEditSyntaxHighlight::UpdateData();
239 0 : }
240 :
241 0 : void OSqlEdit::ImplSetFont()
242 : {
243 0 : AllSettings aSettings = GetSettings();
244 0 : StyleSettings aStyleSettings = aSettings.GetStyleSettings();
245 : rtl::OUString sFontName(
246 : officecfg::Office::Common::Font::SourceViewFont::FontName::get().
247 0 : get_value_or( rtl::OUString() ) );
248 0 : if ( sFontName.isEmpty() )
249 : {
250 0 : Font aTmpFont( OutputDevice::GetDefaultFont( DEFAULTFONT_FIXED, Application::GetSettings().GetUILanguageTag().getLanguageType(), 0 , this ) );
251 0 : sFontName = aTmpFont.GetName();
252 : }
253 : Size aFontSize(
254 0 : 0, officecfg::Office::Common::Font::SourceViewFont::FontHeight::get() );
255 0 : Font aFont( sFontName, aFontSize );
256 0 : aStyleSettings.SetFieldFont(aFont);
257 0 : aSettings.SetStyleSettings(aStyleSettings);
258 0 : SetSettings(aSettings);
259 0 : }
260 :
261 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|