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