xref: /trunk/main/dbaccess/source/ui/control/sqledit.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_dbaccess.hxx"
30 #include "sqledit.hxx"
31 #include "QueryTextView.hxx"
32 #include "querycontainerwindow.hxx"
33 #include <tools/debug.hxx>
34 #include "dbaccess_helpid.hrc"
35 #include "browserids.hxx"
36 #include "querycontroller.hxx"
37 #include "undosqledit.hxx"
38 #include "QueryDesignView.hxx"
39 
40 #include <svl/smplhint.hxx>
41 
42 //////////////////////////////////////////////////////////////////////////
43 // OSqlEdit
44 //------------------------------------------------------------------------------
45 using namespace dbaui;
46 
47 DBG_NAME(OSqlEdit)
48 OSqlEdit::OSqlEdit( OQueryTextView* pParent,  WinBits nWinStyle ) :
49     MultiLineEditSyntaxHighlight( pParent, nWinStyle )
50     ,m_pView(pParent)
51     ,m_bAccelAction( sal_False )
52     ,m_bStopTimer(sal_False )
53 {
54     DBG_CTOR(OSqlEdit,NULL);
55     SetHelpId( HID_CTL_QRYSQLEDIT );
56     SetModifyHdl( LINK(this, OSqlEdit, ModifyHdl) );
57 
58     m_timerUndoActionCreation.SetTimeout(1000);
59     m_timerUndoActionCreation.SetTimeoutHdl(LINK(this, OSqlEdit, OnUndoActionTimer));
60 
61     m_timerInvalidate.SetTimeout(200);
62     m_timerInvalidate.SetTimeoutHdl(LINK(this, OSqlEdit, OnInvalidateTimer));
63     m_timerInvalidate.Start();
64 
65     ImplSetFont();
66     // listen for change of Font and Color Settings
67     m_SourceViewConfig.AddListener( this );
68     m_ColorConfig.AddListener(this);
69 
70     //#i97044#
71     EnableFocusSelectionHide( sal_False );
72 }
73 
74 //------------------------------------------------------------------------------
75 OSqlEdit::~OSqlEdit()
76 {
77     DBG_DTOR(OSqlEdit,NULL);
78     if (m_timerUndoActionCreation.IsActive())
79         m_timerUndoActionCreation.Stop();
80     m_SourceViewConfig.RemoveListener(this);
81     m_ColorConfig.RemoveListener(this);
82 }
83 //------------------------------------------------------------------------------
84 void OSqlEdit::KeyInput( const KeyEvent& rKEvt )
85 {
86     DBG_CHKTHIS(OSqlEdit,NULL);
87     OJoinController& rController = m_pView->getContainerWindow()->getDesignView()->getController();
88     rController.InvalidateFeature(SID_CUT);
89     rController.InvalidateFeature(SID_COPY);
90 
91     // Ist dies ein Cut, Copy, Paste Event?
92     KeyFuncType aKeyFunc = rKEvt.GetKeyCode().GetFunction();
93     if( (aKeyFunc==KEYFUNC_CUT)||(aKeyFunc==KEYFUNC_COPY)||(aKeyFunc==KEYFUNC_PASTE) )
94         m_bAccelAction = sal_True;
95 
96     MultiLineEditSyntaxHighlight::KeyInput( rKEvt );
97 
98     if( m_bAccelAction )
99         m_bAccelAction = sal_False;
100 }
101 
102 //------------------------------------------------------------------------------
103 sal_Bool OSqlEdit::IsInAccelAct()
104 {
105     DBG_CHKTHIS(OSqlEdit,NULL);
106     // Das Cut, Copy, Paste per Accel. fuehrt neben der Aktion im Edit im View
107     // auch die entsprechenden Slots aus. Die  Aktionen finden also zweimal statt.
108     // Um dies zu verhindern, kann im View beim SlotExec diese Funktion
109     // aufgerufen werden.
110 
111     return m_bAccelAction;
112 }
113 
114 //------------------------------------------------------------------------------
115 void OSqlEdit::GetFocus()
116 {
117     DBG_CHKTHIS(OSqlEdit,NULL);
118     m_strOrigText  =GetText();
119     MultiLineEditSyntaxHighlight::GetFocus();
120 }
121 
122 //------------------------------------------------------------------------------
123 IMPL_LINK(OSqlEdit, OnUndoActionTimer, void*, EMPTYARG)
124 {
125     String aText  =GetText();
126     if(aText != m_strOrigText)
127     {
128         OJoinController& rController = m_pView->getContainerWindow()->getDesignView()->getController();
129         SfxUndoManager& rUndoMgr = rController.GetUndoManager();
130         OSqlEditUndoAct* pUndoAct = new OSqlEditUndoAct( this );
131 
132         pUndoAct->SetOriginalText( m_strOrigText );
133         rUndoMgr.AddUndoAction( pUndoAct );
134 
135         rController.InvalidateFeature(SID_UNDO);
136         rController.InvalidateFeature(SID_REDO);
137 
138         m_strOrigText  =aText;
139     }
140 
141     return 0L;
142 }
143 //------------------------------------------------------------------------------
144 IMPL_LINK(OSqlEdit, OnInvalidateTimer, void*, EMPTYARG)
145 {
146     OJoinController& rController = m_pView->getContainerWindow()->getDesignView()->getController();
147     rController.InvalidateFeature(SID_CUT);
148     rController.InvalidateFeature(SID_COPY);
149     if(!m_bStopTimer)
150         m_timerInvalidate.Start();
151     return 0L;
152 }
153 //------------------------------------------------------------------------------
154 IMPL_LINK(OSqlEdit, ModifyHdl, void*, /*EMPTYTAG*/)
155 {
156     if (m_timerUndoActionCreation.IsActive())
157         m_timerUndoActionCreation.Stop();
158     m_timerUndoActionCreation.Start();
159 
160     OJoinController& rController = m_pView->getContainerWindow()->getDesignView()->getController();
161     if (!rController.isModified())
162         rController.setModified( sal_True );
163 
164     rController.InvalidateFeature(SID_SBA_QRY_EXECUTE);
165     rController.InvalidateFeature(SID_CUT);
166     rController.InvalidateFeature(SID_COPY);
167 
168     m_lnkTextModifyHdl.Call(NULL);
169     return 0;
170 }
171 
172 //------------------------------------------------------------------------------
173 void OSqlEdit::SetText(const String& rNewText)
174 {
175     DBG_CHKTHIS(OSqlEdit,NULL);
176     if (m_timerUndoActionCreation.IsActive())
177     {   // die noch anstehenden Undo-Action erzeugen
178         m_timerUndoActionCreation.Stop();
179         LINK(this, OSqlEdit, OnUndoActionTimer).Call(NULL);
180     }
181 
182     MultiLineEditSyntaxHighlight::SetText(rNewText);
183     m_strOrigText  =rNewText;
184 }
185 // -----------------------------------------------------------------------------
186 void OSqlEdit::stopTimer()
187 {
188     m_bStopTimer = sal_True;
189     if (m_timerInvalidate.IsActive())
190         m_timerInvalidate.Stop();
191 }
192 // -----------------------------------------------------------------------------
193 void OSqlEdit::startTimer()
194 {
195     m_bStopTimer = sal_False;
196     if (!m_timerInvalidate.IsActive())
197         m_timerInvalidate.Start();
198 }
199 
200 void OSqlEdit::ConfigurationChanged( utl::ConfigurationBroadcaster* pOption, sal_uInt32 )
201 {
202     if ( pOption == &m_SourceViewConfig )
203         ImplSetFont();
204     else if ( pOption == &m_ColorConfig )
205         MultiLineEditSyntaxHighlight::UpdateData();
206 }
207 
208 void OSqlEdit::ImplSetFont()
209 {
210     AllSettings aSettings = GetSettings();
211     StyleSettings aStyleSettings = aSettings.GetStyleSettings();
212     String sFontName = m_SourceViewConfig.GetFontName();
213     if ( !sFontName.Len() )
214     {
215         Font aTmpFont( OutputDevice::GetDefaultFont( DEFAULTFONT_FIXED, Application::GetSettings().GetUILanguage(), 0 , this ) );
216         sFontName = aTmpFont.GetName();
217     }
218     Size aFontSize( 0, m_SourceViewConfig.GetFontHeight() );
219     Font aFont( sFontName, aFontSize );
220     aStyleSettings.SetFieldFont(aFont);
221     aSettings.SetStyleSettings(aStyleSettings);
222     SetSettings(aSettings);
223 }
224 //==============================================================================
225