Version 3.6.0.2, tag libreoffice-3.6.0.2
[LibreOffice.git] / dbaccess / source / ui / control / sqledit.cxx
blob3161879ee7ab853863f10206ccaa31604ac27219
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "sal/config.h"
31 #include <cassert>
33 #include "com/sun/star/beans/XMultiPropertySet.hpp"
34 #include "com/sun/star/beans/XPropertiesChangeListener.hpp"
35 #include "officecfg/Office/Common.hxx"
36 #include "sqledit.hxx"
37 #include "QueryTextView.hxx"
38 #include "querycontainerwindow.hxx"
39 #include <tools/debug.hxx>
40 #include "dbaccess_helpid.hrc"
41 #include "browserids.hxx"
42 #include "querycontroller.hxx"
43 #include "undosqledit.hxx"
44 #include "QueryDesignView.hxx"
46 #include <svl/smplhint.hxx>
48 namespace css = ::com::sun::star;
50 //////////////////////////////////////////////////////////////////////////
51 // OSqlEdit
52 //------------------------------------------------------------------------------
53 using namespace dbaui;
55 class OSqlEdit::ChangesListener:
56 public cppu::WeakImplHelper1< css::beans::XPropertiesChangeListener >
58 public:
59 ChangesListener(OSqlEdit & editor): editor_(editor) {}
61 private:
62 virtual ~ChangesListener() {}
64 virtual void SAL_CALL disposing(css::lang::EventObject const &)
65 throw (css::uno::RuntimeException)
67 osl::MutexGuard g(editor_.m_mutex);
68 editor_.m_notifier.clear();
71 virtual void SAL_CALL propertiesChange(
72 css::uno::Sequence< css::beans::PropertyChangeEvent > const &)
73 throw (css::uno::RuntimeException)
75 SolarMutexGuard g;
76 editor_.ImplSetFont();
79 OSqlEdit & editor_;
82 DBG_NAME(OSqlEdit)
83 OSqlEdit::OSqlEdit( OQueryTextView* pParent, WinBits nWinStyle ) :
84 MultiLineEditSyntaxHighlight( pParent, nWinStyle )
85 ,m_pView(pParent)
86 ,m_bAccelAction( sal_False )
87 ,m_bStopTimer(sal_False )
89 DBG_CTOR(OSqlEdit,NULL);
90 SetHelpId( HID_CTL_QRYSQLEDIT );
91 SetModifyHdl( LINK(this, OSqlEdit, ModifyHdl) );
93 m_timerUndoActionCreation.SetTimeout(1000);
94 m_timerUndoActionCreation.SetTimeoutHdl(LINK(this, OSqlEdit, OnUndoActionTimer));
96 m_timerInvalidate.SetTimeout(200);
97 m_timerInvalidate.SetTimeoutHdl(LINK(this, OSqlEdit, OnInvalidateTimer));
98 m_timerInvalidate.Start();
100 ImplSetFont();
101 // Listen for change of Font and Color Settings:
102 // Using "this" in ctor is a little fishy, but should work here at least as
103 // long as there are no derivations:
104 m_listener = new ChangesListener(*this);
105 css::uno::Reference< css::beans::XMultiPropertySet > n(
106 officecfg::Office::Common::Font::SourceViewFont::get(),
107 css::uno::UNO_QUERY_THROW);
109 osl::MutexGuard g(m_mutex);
110 m_notifier = n;
112 css::uno::Sequence< rtl::OUString > s(2);
113 s[0] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FontHeight"));
114 s[1] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FontName"));
115 n->addPropertiesChangeListener(s, m_listener.get());
116 m_ColorConfig.AddListener(this);
118 //#i97044#
119 EnableFocusSelectionHide( sal_False );
122 //------------------------------------------------------------------------------
123 OSqlEdit::~OSqlEdit()
125 DBG_DTOR(OSqlEdit,NULL);
126 if (m_timerUndoActionCreation.IsActive())
127 m_timerUndoActionCreation.Stop();
128 css::uno::Reference< css::beans::XMultiPropertySet > n;
130 osl::MutexGuard g(m_mutex);
131 n = m_notifier;
133 if (n.is()) {
134 n->removePropertiesChangeListener(m_listener.get());
136 m_ColorConfig.RemoveListener(this);
138 //------------------------------------------------------------------------------
139 void OSqlEdit::KeyInput( const KeyEvent& rKEvt )
141 DBG_CHKTHIS(OSqlEdit,NULL);
142 OJoinController& rController = m_pView->getContainerWindow()->getDesignView()->getController();
143 rController.InvalidateFeature(SID_CUT);
144 rController.InvalidateFeature(SID_COPY);
146 // Ist dies ein Cut, Copy, Paste Event?
147 KeyFuncType aKeyFunc = rKEvt.GetKeyCode().GetFunction();
148 if( (aKeyFunc==KEYFUNC_CUT)||(aKeyFunc==KEYFUNC_COPY)||(aKeyFunc==KEYFUNC_PASTE) )
149 m_bAccelAction = sal_True;
151 MultiLineEditSyntaxHighlight::KeyInput( rKEvt );
153 if( m_bAccelAction )
154 m_bAccelAction = sal_False;
157 //------------------------------------------------------------------------------
158 sal_Bool OSqlEdit::IsInAccelAct()
160 DBG_CHKTHIS(OSqlEdit,NULL);
161 // Das Cut, Copy, Paste per Accel. fuehrt neben der Aktion im Edit im View
162 // auch die entsprechenden Slots aus. Die Aktionen finden also zweimal statt.
163 // Um dies zu verhindern, kann im View beim SlotExec diese Funktion
164 // aufgerufen werden.
166 return m_bAccelAction;
169 //------------------------------------------------------------------------------
170 void OSqlEdit::GetFocus()
172 DBG_CHKTHIS(OSqlEdit,NULL);
173 m_strOrigText =GetText();
174 MultiLineEditSyntaxHighlight::GetFocus();
177 //------------------------------------------------------------------------------
178 IMPL_LINK_NOARG(OSqlEdit, OnUndoActionTimer)
180 String aText =GetText();
181 if(aText != m_strOrigText)
183 OJoinController& rController = m_pView->getContainerWindow()->getDesignView()->getController();
184 SfxUndoManager& rUndoMgr = rController.GetUndoManager();
185 OSqlEditUndoAct* pUndoAct = new OSqlEditUndoAct( this );
187 pUndoAct->SetOriginalText( m_strOrigText );
188 rUndoMgr.AddUndoAction( pUndoAct );
190 rController.InvalidateFeature(SID_UNDO);
191 rController.InvalidateFeature(SID_REDO);
193 m_strOrigText =aText;
196 return 0L;
198 //------------------------------------------------------------------------------
199 IMPL_LINK_NOARG(OSqlEdit, OnInvalidateTimer)
201 OJoinController& rController = m_pView->getContainerWindow()->getDesignView()->getController();
202 rController.InvalidateFeature(SID_CUT);
203 rController.InvalidateFeature(SID_COPY);
204 if(!m_bStopTimer)
205 m_timerInvalidate.Start();
206 return 0L;
208 //------------------------------------------------------------------------------
209 IMPL_LINK(OSqlEdit, ModifyHdl, void*, /*EMPTYTAG*/)
211 if (m_timerUndoActionCreation.IsActive())
212 m_timerUndoActionCreation.Stop();
213 m_timerUndoActionCreation.Start();
215 OJoinController& rController = m_pView->getContainerWindow()->getDesignView()->getController();
216 if (!rController.isModified())
217 rController.setModified( sal_True );
219 rController.InvalidateFeature(SID_SBA_QRY_EXECUTE);
220 rController.InvalidateFeature(SID_CUT);
221 rController.InvalidateFeature(SID_COPY);
223 m_lnkTextModifyHdl.Call(NULL);
224 return 0;
227 //------------------------------------------------------------------------------
228 void OSqlEdit::SetText(const String& rNewText)
230 DBG_CHKTHIS(OSqlEdit,NULL);
231 if (m_timerUndoActionCreation.IsActive())
232 { // die noch anstehenden Undo-Action erzeugen
233 m_timerUndoActionCreation.Stop();
234 LINK(this, OSqlEdit, OnUndoActionTimer).Call(NULL);
237 MultiLineEditSyntaxHighlight::SetText(rNewText);
238 m_strOrigText =rNewText;
240 // -----------------------------------------------------------------------------
241 void OSqlEdit::stopTimer()
243 m_bStopTimer = sal_True;
244 if (m_timerInvalidate.IsActive())
245 m_timerInvalidate.Stop();
247 // -----------------------------------------------------------------------------
248 void OSqlEdit::startTimer()
250 m_bStopTimer = sal_False;
251 if (!m_timerInvalidate.IsActive())
252 m_timerInvalidate.Start();
255 void OSqlEdit::ConfigurationChanged( utl::ConfigurationBroadcaster* pOption, sal_uInt32 )
257 assert( pOption == &m_ColorConfig );
258 (void) pOption; // avoid warnings
259 MultiLineEditSyntaxHighlight::UpdateData();
262 void OSqlEdit::ImplSetFont()
264 AllSettings aSettings = GetSettings();
265 StyleSettings aStyleSettings = aSettings.GetStyleSettings();
266 rtl::OUString sFontName(
267 officecfg::Office::Common::Font::SourceViewFont::FontName::get().
268 get_value_or( rtl::OUString() ) );
269 if ( sFontName.isEmpty() )
271 Font aTmpFont( OutputDevice::GetDefaultFont( DEFAULTFONT_FIXED, Application::GetSettings().GetUILanguage(), 0 , this ) );
272 sFontName = aTmpFont.GetName();
274 Size aFontSize(
275 0, officecfg::Office::Common::Font::SourceViewFont::FontHeight::get() );
276 Font aFont( sFontName, aFontSize );
277 aStyleSettings.SetFieldFont(aFont);
278 aSettings.SetStyleSettings(aStyleSettings);
279 SetSettings(aSettings);
281 //==============================================================================
283 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */