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