update dev300-m58
[ooovba.git] / dbaccess / source / ui / control / sqledit.cxx
blobbca065c12d41f8c014444fad6087ec6817addb5b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sqledit.cxx,v $
10 * $Revision: 1.12.16.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
33 #include "sqledit.hxx"
34 #include "QueryTextView.hxx"
35 #include "querycontainerwindow.hxx"
36 #include <tools/debug.hxx>
37 #include "dbaccess_helpid.hrc"
38 #include "browserids.hxx"
39 #include "querycontroller.hxx"
40 #include "undosqledit.hxx"
41 #include "QueryDesignView.hxx"
43 #include <svtools/smplhint.hxx>
45 //////////////////////////////////////////////////////////////////////////
46 // OSqlEdit
47 //------------------------------------------------------------------------------
48 using namespace dbaui;
50 DBG_NAME(OSqlEdit)
51 OSqlEdit::OSqlEdit( OQueryTextView* pParent, WinBits nWinStyle ) :
52 MultiLineEditSyntaxHighlight( pParent, nWinStyle )
53 ,m_pView(pParent)
54 ,m_bAccelAction( sal_False )
55 ,m_bStopTimer(sal_False )
57 DBG_CTOR(OSqlEdit,NULL);
58 SetHelpId( HID_CTL_QRYSQLEDIT );
59 SetModifyHdl( LINK(this, OSqlEdit, ModifyHdl) );
61 m_timerUndoActionCreation.SetTimeout(1000);
62 m_timerUndoActionCreation.SetTimeoutHdl(LINK(this, OSqlEdit, OnUndoActionTimer));
64 m_timerInvalidate.SetTimeout(200);
65 m_timerInvalidate.SetTimeoutHdl(LINK(this, OSqlEdit, OnInvalidateTimer));
66 m_timerInvalidate.Start();
68 ImplSetFont();
69 // listen for change of Font and Color Settings
70 StartListening(m_SourceViewConfig);
71 StartListening(m_ColorConfig);
73 //#i97044#
74 EnableFocusSelectionHide( FALSE );
77 //------------------------------------------------------------------------------
78 OSqlEdit::~OSqlEdit()
80 DBG_DTOR(OSqlEdit,NULL);
81 if (m_timerUndoActionCreation.IsActive())
82 m_timerUndoActionCreation.Stop();
83 EndListening(m_SourceViewConfig);
84 EndListening(m_ColorConfig);
86 //------------------------------------------------------------------------------
87 void OSqlEdit::KeyInput( const KeyEvent& rKEvt )
89 DBG_CHKTHIS(OSqlEdit,NULL);
90 m_pView->getContainerWindow()->getDesignView()->getController().InvalidateFeature(SID_CUT);
91 m_pView->getContainerWindow()->getDesignView()->getController().InvalidateFeature(SID_COPY);
93 // Ist dies ein Cut, Copy, Paste Event?
94 KeyFuncType aKeyFunc = rKEvt.GetKeyCode().GetFunction();
95 if( (aKeyFunc==KEYFUNC_CUT)||(aKeyFunc==KEYFUNC_COPY)||(aKeyFunc==KEYFUNC_PASTE) )
96 m_bAccelAction = sal_True;
98 MultiLineEditSyntaxHighlight::KeyInput( rKEvt );
100 if( m_bAccelAction )
101 m_bAccelAction = sal_False;
104 //------------------------------------------------------------------------------
105 sal_Bool OSqlEdit::IsInAccelAct()
107 DBG_CHKTHIS(OSqlEdit,NULL);
108 // Das Cut, Copy, Paste per Accel. fuehrt neben der Aktion im Edit im View
109 // auch die entsprechenden Slots aus. Die Aktionen finden also zweimal statt.
110 // Um dies zu verhindern, kann im View beim SlotExec diese Funktion
111 // aufgerufen werden.
113 return m_bAccelAction;
116 //------------------------------------------------------------------------------
117 void OSqlEdit::GetFocus()
119 DBG_CHKTHIS(OSqlEdit,NULL);
120 m_strOrigText =GetText();
121 MultiLineEditSyntaxHighlight::GetFocus();
124 //------------------------------------------------------------------------------
125 IMPL_LINK(OSqlEdit, OnUndoActionTimer, void*, EMPTYARG)
127 String aText =GetText();
128 if(aText != m_strOrigText)
130 SfxUndoManager* pUndoMgr = m_pView->getContainerWindow()->getDesignView()->getController().getUndoMgr();
131 OSqlEditUndoAct* pUndoAct = new OSqlEditUndoAct( this );
133 pUndoAct->SetOriginalText( m_strOrigText );
134 pUndoMgr->AddUndoAction( pUndoAct );
136 m_pView->getContainerWindow()->getDesignView()->getController().InvalidateFeature(SID_UNDO);
137 m_pView->getContainerWindow()->getDesignView()->getController().InvalidateFeature(SID_REDO);
139 m_strOrigText =aText;
142 return 0L;
144 //------------------------------------------------------------------------------
145 IMPL_LINK(OSqlEdit, OnInvalidateTimer, void*, EMPTYARG)
147 m_pView->getContainerWindow()->getDesignView()->getController().InvalidateFeature(SID_CUT);
148 m_pView->getContainerWindow()->getDesignView()->getController().InvalidateFeature(SID_COPY);
149 if(!m_bStopTimer)
150 m_timerInvalidate.Start();
151 return 0L;
153 //------------------------------------------------------------------------------
154 IMPL_LINK(OSqlEdit, ModifyHdl, void*, /*EMPTYTAG*/)
156 if (m_timerUndoActionCreation.IsActive())
157 m_timerUndoActionCreation.Stop();
158 m_timerUndoActionCreation.Start();
160 if (!m_pView->getContainerWindow()->getDesignView()->getController().isModified())
161 m_pView->getContainerWindow()->getDesignView()->getController().setModified( sal_True );
163 m_pView->getContainerWindow()->getDesignView()->getController().InvalidateFeature(SID_SBA_QRY_EXECUTE);
164 m_pView->getContainerWindow()->getDesignView()->getController().InvalidateFeature(SID_CUT);
165 m_pView->getContainerWindow()->getDesignView()->getController().InvalidateFeature(SID_COPY);
167 m_lnkTextModifyHdl.Call(NULL);
168 return 0;
171 //------------------------------------------------------------------------------
172 void OSqlEdit::SetText(const String& rNewText)
174 DBG_CHKTHIS(OSqlEdit,NULL);
175 if (m_timerUndoActionCreation.IsActive())
176 { // die noch anstehenden Undo-Action erzeugen
177 m_timerUndoActionCreation.Stop();
178 LINK(this, OSqlEdit, OnUndoActionTimer).Call(NULL);
181 MultiLineEditSyntaxHighlight::SetText(rNewText);
182 m_strOrigText =rNewText;
184 // -----------------------------------------------------------------------------
185 void OSqlEdit::stopTimer()
187 m_bStopTimer = sal_True;
188 if (m_timerInvalidate.IsActive())
189 m_timerInvalidate.Stop();
191 // -----------------------------------------------------------------------------
192 void OSqlEdit::startTimer()
194 m_bStopTimer = sal_False;
195 if (!m_timerInvalidate.IsActive())
196 m_timerInvalidate.Start();
199 void OSqlEdit::Notify( SfxBroadcaster& rBC, const SfxHint& /*rHint*/ )
201 if (&rBC == &m_SourceViewConfig)
202 ImplSetFont();
203 else if (&rBC == &m_ColorConfig)
204 MultiLineEditSyntaxHighlight::UpdateData();
207 void OSqlEdit::ImplSetFont()
209 AllSettings aSettings = GetSettings();
210 StyleSettings aStyleSettings = aSettings.GetStyleSettings();
211 String sFontName = m_SourceViewConfig.GetFontName();
212 if ( !sFontName.Len() )
214 Font aTmpFont( OutputDevice::GetDefaultFont( DEFAULTFONT_FIXED, Application::GetSettings().GetUILanguage(), 0 , this ) );
215 sFontName = aTmpFont.GetName();
217 Size aFontSize( 0, m_SourceViewConfig.GetFontHeight() );
218 Font aFont( sFontName, aFontSize );
219 aStyleSettings.SetFieldFont(aFont);
220 aSettings.SetStyleSettings(aStyleSettings);
221 SetSettings(aSettings);
223 //==============================================================================