196de5490SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
396de5490SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
496de5490SAndrew Rist * or more contributor license agreements. See the NOTICE file
596de5490SAndrew Rist * distributed with this work for additional information
696de5490SAndrew Rist * regarding copyright ownership. The ASF licenses this file
796de5490SAndrew Rist * to you under the Apache License, Version 2.0 (the
896de5490SAndrew Rist * "License"); you may not use this file except in compliance
996de5490SAndrew Rist * with the License. You may obtain a copy of the License at
1096de5490SAndrew Rist *
1196de5490SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
1296de5490SAndrew Rist *
1396de5490SAndrew Rist * Unless required by applicable law or agreed to in writing,
1496de5490SAndrew Rist * software distributed under the License is distributed on an
1596de5490SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1696de5490SAndrew Rist * KIND, either express or implied. See the License for the
1796de5490SAndrew Rist * specific language governing permissions and limitations
1896de5490SAndrew Rist * under the License.
1996de5490SAndrew Rist *
2096de5490SAndrew Rist *************************************************************/
2196de5490SAndrew Rist
2296de5490SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25*b63233d8Sdamjan #include "precompiled_dbui.hxx"
26cdf0e10cSrcweir #include "sqledit.hxx"
27cdf0e10cSrcweir #include "QueryTextView.hxx"
28cdf0e10cSrcweir #include "querycontainerwindow.hxx"
29cdf0e10cSrcweir #include <tools/debug.hxx>
30cdf0e10cSrcweir #include "dbaccess_helpid.hrc"
31cdf0e10cSrcweir #include "browserids.hxx"
32cdf0e10cSrcweir #include "querycontroller.hxx"
33cdf0e10cSrcweir #include "undosqledit.hxx"
34cdf0e10cSrcweir #include "QueryDesignView.hxx"
35cdf0e10cSrcweir
36cdf0e10cSrcweir #include <svl/smplhint.hxx>
37cdf0e10cSrcweir
38cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////
39cdf0e10cSrcweir // OSqlEdit
40cdf0e10cSrcweir //------------------------------------------------------------------------------
41cdf0e10cSrcweir using namespace dbaui;
42cdf0e10cSrcweir
DBG_NAME(OSqlEdit)43cdf0e10cSrcweir DBG_NAME(OSqlEdit)
44cdf0e10cSrcweir OSqlEdit::OSqlEdit( OQueryTextView* pParent, WinBits nWinStyle ) :
45cdf0e10cSrcweir MultiLineEditSyntaxHighlight( pParent, nWinStyle )
46cdf0e10cSrcweir ,m_pView(pParent)
47cdf0e10cSrcweir ,m_bAccelAction( sal_False )
48cdf0e10cSrcweir ,m_bStopTimer(sal_False )
49cdf0e10cSrcweir {
50cdf0e10cSrcweir DBG_CTOR(OSqlEdit,NULL);
51cdf0e10cSrcweir SetHelpId( HID_CTL_QRYSQLEDIT );
52cdf0e10cSrcweir SetModifyHdl( LINK(this, OSqlEdit, ModifyHdl) );
53cdf0e10cSrcweir
54cdf0e10cSrcweir m_timerUndoActionCreation.SetTimeout(1000);
55cdf0e10cSrcweir m_timerUndoActionCreation.SetTimeoutHdl(LINK(this, OSqlEdit, OnUndoActionTimer));
56cdf0e10cSrcweir
57cdf0e10cSrcweir m_timerInvalidate.SetTimeout(200);
58cdf0e10cSrcweir m_timerInvalidate.SetTimeoutHdl(LINK(this, OSqlEdit, OnInvalidateTimer));
59cdf0e10cSrcweir m_timerInvalidate.Start();
60cdf0e10cSrcweir
61cdf0e10cSrcweir ImplSetFont();
62cdf0e10cSrcweir // listen for change of Font and Color Settings
63cdf0e10cSrcweir m_SourceViewConfig.AddListener( this );
64cdf0e10cSrcweir m_ColorConfig.AddListener(this);
65cdf0e10cSrcweir
66cdf0e10cSrcweir //#i97044#
67cdf0e10cSrcweir EnableFocusSelectionHide( sal_False );
68cdf0e10cSrcweir }
69cdf0e10cSrcweir
70cdf0e10cSrcweir //------------------------------------------------------------------------------
~OSqlEdit()71cdf0e10cSrcweir OSqlEdit::~OSqlEdit()
72cdf0e10cSrcweir {
73cdf0e10cSrcweir DBG_DTOR(OSqlEdit,NULL);
74cdf0e10cSrcweir if (m_timerUndoActionCreation.IsActive())
75cdf0e10cSrcweir m_timerUndoActionCreation.Stop();
76cdf0e10cSrcweir m_SourceViewConfig.RemoveListener(this);
77cdf0e10cSrcweir m_ColorConfig.RemoveListener(this);
78cdf0e10cSrcweir }
79cdf0e10cSrcweir //------------------------------------------------------------------------------
KeyInput(const KeyEvent & rKEvt)80cdf0e10cSrcweir void OSqlEdit::KeyInput( const KeyEvent& rKEvt )
81cdf0e10cSrcweir {
82cdf0e10cSrcweir DBG_CHKTHIS(OSqlEdit,NULL);
83cdf0e10cSrcweir OJoinController& rController = m_pView->getContainerWindow()->getDesignView()->getController();
84cdf0e10cSrcweir rController.InvalidateFeature(SID_CUT);
85cdf0e10cSrcweir rController.InvalidateFeature(SID_COPY);
86cdf0e10cSrcweir
87cdf0e10cSrcweir // Ist dies ein Cut, Copy, Paste Event?
88cdf0e10cSrcweir KeyFuncType aKeyFunc = rKEvt.GetKeyCode().GetFunction();
89cdf0e10cSrcweir if( (aKeyFunc==KEYFUNC_CUT)||(aKeyFunc==KEYFUNC_COPY)||(aKeyFunc==KEYFUNC_PASTE) )
90cdf0e10cSrcweir m_bAccelAction = sal_True;
91cdf0e10cSrcweir
92cdf0e10cSrcweir MultiLineEditSyntaxHighlight::KeyInput( rKEvt );
93cdf0e10cSrcweir
94cdf0e10cSrcweir if( m_bAccelAction )
95cdf0e10cSrcweir m_bAccelAction = sal_False;
96cdf0e10cSrcweir }
97cdf0e10cSrcweir
98cdf0e10cSrcweir //------------------------------------------------------------------------------
IsInAccelAct()99cdf0e10cSrcweir sal_Bool OSqlEdit::IsInAccelAct()
100cdf0e10cSrcweir {
101cdf0e10cSrcweir DBG_CHKTHIS(OSqlEdit,NULL);
102cdf0e10cSrcweir // Das Cut, Copy, Paste per Accel. fuehrt neben der Aktion im Edit im View
103cdf0e10cSrcweir // auch die entsprechenden Slots aus. Die Aktionen finden also zweimal statt.
104cdf0e10cSrcweir // Um dies zu verhindern, kann im View beim SlotExec diese Funktion
105cdf0e10cSrcweir // aufgerufen werden.
106cdf0e10cSrcweir
107cdf0e10cSrcweir return m_bAccelAction;
108cdf0e10cSrcweir }
109cdf0e10cSrcweir
110cdf0e10cSrcweir //------------------------------------------------------------------------------
GetFocus()111cdf0e10cSrcweir void OSqlEdit::GetFocus()
112cdf0e10cSrcweir {
113cdf0e10cSrcweir DBG_CHKTHIS(OSqlEdit,NULL);
114cdf0e10cSrcweir m_strOrigText =GetText();
115cdf0e10cSrcweir MultiLineEditSyntaxHighlight::GetFocus();
116cdf0e10cSrcweir }
117cdf0e10cSrcweir
118cdf0e10cSrcweir //------------------------------------------------------------------------------
IMPL_LINK(OSqlEdit,OnUndoActionTimer,void *,EMPTYARG)119cdf0e10cSrcweir IMPL_LINK(OSqlEdit, OnUndoActionTimer, void*, EMPTYARG)
120cdf0e10cSrcweir {
121cdf0e10cSrcweir String aText =GetText();
122cdf0e10cSrcweir if(aText != m_strOrigText)
123cdf0e10cSrcweir {
124cdf0e10cSrcweir OJoinController& rController = m_pView->getContainerWindow()->getDesignView()->getController();
125cdf0e10cSrcweir SfxUndoManager& rUndoMgr = rController.GetUndoManager();
126cdf0e10cSrcweir OSqlEditUndoAct* pUndoAct = new OSqlEditUndoAct( this );
127cdf0e10cSrcweir
128cdf0e10cSrcweir pUndoAct->SetOriginalText( m_strOrigText );
129cdf0e10cSrcweir rUndoMgr.AddUndoAction( pUndoAct );
130cdf0e10cSrcweir
131cdf0e10cSrcweir rController.InvalidateFeature(SID_UNDO);
132cdf0e10cSrcweir rController.InvalidateFeature(SID_REDO);
133cdf0e10cSrcweir
134cdf0e10cSrcweir m_strOrigText =aText;
135cdf0e10cSrcweir }
136cdf0e10cSrcweir
137cdf0e10cSrcweir return 0L;
138cdf0e10cSrcweir }
139cdf0e10cSrcweir //------------------------------------------------------------------------------
IMPL_LINK(OSqlEdit,OnInvalidateTimer,void *,EMPTYARG)140cdf0e10cSrcweir IMPL_LINK(OSqlEdit, OnInvalidateTimer, void*, EMPTYARG)
141cdf0e10cSrcweir {
142cdf0e10cSrcweir OJoinController& rController = m_pView->getContainerWindow()->getDesignView()->getController();
143cdf0e10cSrcweir rController.InvalidateFeature(SID_CUT);
144cdf0e10cSrcweir rController.InvalidateFeature(SID_COPY);
145cdf0e10cSrcweir if(!m_bStopTimer)
146cdf0e10cSrcweir m_timerInvalidate.Start();
147cdf0e10cSrcweir return 0L;
148cdf0e10cSrcweir }
149cdf0e10cSrcweir //------------------------------------------------------------------------------
150cdf0e10cSrcweir IMPL_LINK(OSqlEdit, ModifyHdl, void*, /*EMPTYTAG*/)
151cdf0e10cSrcweir {
152cdf0e10cSrcweir if (m_timerUndoActionCreation.IsActive())
153cdf0e10cSrcweir m_timerUndoActionCreation.Stop();
154cdf0e10cSrcweir m_timerUndoActionCreation.Start();
155cdf0e10cSrcweir
156cdf0e10cSrcweir OJoinController& rController = m_pView->getContainerWindow()->getDesignView()->getController();
157cdf0e10cSrcweir if (!rController.isModified())
158cdf0e10cSrcweir rController.setModified( sal_True );
159cdf0e10cSrcweir
160cdf0e10cSrcweir rController.InvalidateFeature(SID_SBA_QRY_EXECUTE);
161cdf0e10cSrcweir rController.InvalidateFeature(SID_CUT);
162cdf0e10cSrcweir rController.InvalidateFeature(SID_COPY);
163cdf0e10cSrcweir
164cdf0e10cSrcweir m_lnkTextModifyHdl.Call(NULL);
165cdf0e10cSrcweir return 0;
166cdf0e10cSrcweir }
167cdf0e10cSrcweir
168cdf0e10cSrcweir //------------------------------------------------------------------------------
SetText(const String & rNewText)169cdf0e10cSrcweir void OSqlEdit::SetText(const String& rNewText)
170cdf0e10cSrcweir {
171cdf0e10cSrcweir DBG_CHKTHIS(OSqlEdit,NULL);
172cdf0e10cSrcweir if (m_timerUndoActionCreation.IsActive())
173cdf0e10cSrcweir { // die noch anstehenden Undo-Action erzeugen
174cdf0e10cSrcweir m_timerUndoActionCreation.Stop();
175cdf0e10cSrcweir LINK(this, OSqlEdit, OnUndoActionTimer).Call(NULL);
176cdf0e10cSrcweir }
177cdf0e10cSrcweir
178cdf0e10cSrcweir MultiLineEditSyntaxHighlight::SetText(rNewText);
179cdf0e10cSrcweir m_strOrigText =rNewText;
180cdf0e10cSrcweir }
181cdf0e10cSrcweir // -----------------------------------------------------------------------------
stopTimer()182cdf0e10cSrcweir void OSqlEdit::stopTimer()
183cdf0e10cSrcweir {
184cdf0e10cSrcweir m_bStopTimer = sal_True;
185cdf0e10cSrcweir if (m_timerInvalidate.IsActive())
186cdf0e10cSrcweir m_timerInvalidate.Stop();
187cdf0e10cSrcweir }
188cdf0e10cSrcweir // -----------------------------------------------------------------------------
startTimer()189cdf0e10cSrcweir void OSqlEdit::startTimer()
190cdf0e10cSrcweir {
191cdf0e10cSrcweir m_bStopTimer = sal_False;
192cdf0e10cSrcweir if (!m_timerInvalidate.IsActive())
193cdf0e10cSrcweir m_timerInvalidate.Start();
194cdf0e10cSrcweir }
195cdf0e10cSrcweir
ConfigurationChanged(utl::ConfigurationBroadcaster * pOption,sal_uInt32)196cdf0e10cSrcweir void OSqlEdit::ConfigurationChanged( utl::ConfigurationBroadcaster* pOption, sal_uInt32 )
197cdf0e10cSrcweir {
198cdf0e10cSrcweir if ( pOption == &m_SourceViewConfig )
199cdf0e10cSrcweir ImplSetFont();
200cdf0e10cSrcweir else if ( pOption == &m_ColorConfig )
201cdf0e10cSrcweir MultiLineEditSyntaxHighlight::UpdateData();
202cdf0e10cSrcweir }
203cdf0e10cSrcweir
ImplSetFont()204cdf0e10cSrcweir void OSqlEdit::ImplSetFont()
205cdf0e10cSrcweir {
206cdf0e10cSrcweir AllSettings aSettings = GetSettings();
207cdf0e10cSrcweir StyleSettings aStyleSettings = aSettings.GetStyleSettings();
208cdf0e10cSrcweir String sFontName = m_SourceViewConfig.GetFontName();
209cdf0e10cSrcweir if ( !sFontName.Len() )
210cdf0e10cSrcweir {
211cdf0e10cSrcweir Font aTmpFont( OutputDevice::GetDefaultFont( DEFAULTFONT_FIXED, Application::GetSettings().GetUILanguage(), 0 , this ) );
212cdf0e10cSrcweir sFontName = aTmpFont.GetName();
213cdf0e10cSrcweir }
214cdf0e10cSrcweir Size aFontSize( 0, m_SourceViewConfig.GetFontHeight() );
215cdf0e10cSrcweir Font aFont( sFontName, aFontSize );
216cdf0e10cSrcweir aStyleSettings.SetFieldFont(aFont);
217cdf0e10cSrcweir aSettings.SetStyleSettings(aStyleSettings);
218cdf0e10cSrcweir SetSettings(aSettings);
219cdf0e10cSrcweir }
220cdf0e10cSrcweir //==============================================================================
221