LCOV - code coverage report
Current view: top level - dbaccess/source/ui/control - sqledit.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 120 0.8 %
Date: 2014-11-03 Functions: 2 23 8.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "sal/config.h"
      21             : 
      22             : #include <cassert>
      23             : 
      24             : #include "com/sun/star/beans/XMultiPropertySet.hpp"
      25             : #include "com/sun/star/beans/XPropertiesChangeListener.hpp"
      26             : #include "officecfg/Office/Common.hxx"
      27             : #include "sqledit.hxx"
      28             : #include "QueryTextView.hxx"
      29             : #include "querycontainerwindow.hxx"
      30             : #include <tools/debug.hxx>
      31             : #include "dbaccess_helpid.hrc"
      32             : #include "browserids.hxx"
      33             : #include "querycontroller.hxx"
      34             : #include "undosqledit.hxx"
      35             : #include "QueryDesignView.hxx"
      36             : #include <svl/smplhint.hxx>
      37             : #include <vcl/settings.hxx>
      38             : 
      39             : using namespace dbaui;
      40             : 
      41             : class OSqlEdit::ChangesListener:
      42             :     public cppu::WeakImplHelper1< css::beans::XPropertiesChangeListener >
      43             : {
      44             : public:
      45           0 :     ChangesListener(OSqlEdit & editor): editor_(editor) {}
      46             : 
      47             : private:
      48           0 :     virtual ~ChangesListener() {}
      49             : 
      50           0 :     virtual void SAL_CALL disposing(css::lang::EventObject const &)
      51             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      52             :     {
      53           0 :         osl::MutexGuard g(editor_.m_mutex);
      54           0 :         editor_.m_notifier.clear();
      55           0 :     }
      56             : 
      57           0 :     virtual void SAL_CALL propertiesChange(
      58             :         css::uno::Sequence< css::beans::PropertyChangeEvent > const &)
      59             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      60             :     {
      61           0 :         SolarMutexGuard g;
      62           0 :         editor_.ImplSetFont();
      63           0 :     }
      64             : 
      65             :     OSqlEdit & editor_;
      66             : };
      67             : 
      68           0 : OSqlEdit::OSqlEdit( OQueryTextView* pParent,  WinBits nWinStyle ) :
      69             :     MultiLineEditSyntaxHighlight( pParent, nWinStyle )
      70             :     ,m_pView(pParent)
      71             :     ,m_bAccelAction( false )
      72           0 :     ,m_bStopTimer(false )
      73             : {
      74           0 :     SetHelpId( HID_CTL_QRYSQLEDIT );
      75           0 :     SetModifyHdl( LINK(this, OSqlEdit, ModifyHdl) );
      76             : 
      77           0 :     m_timerUndoActionCreation.SetTimeout(1000);
      78           0 :     m_timerUndoActionCreation.SetTimeoutHdl(LINK(this, OSqlEdit, OnUndoActionTimer));
      79             : 
      80           0 :     m_timerInvalidate.SetTimeout(200);
      81           0 :     m_timerInvalidate.SetTimeoutHdl(LINK(this, OSqlEdit, OnInvalidateTimer));
      82           0 :     m_timerInvalidate.Start();
      83             : 
      84           0 :     ImplSetFont();
      85             :     // Listen for change of Font and Color Settings:
      86             :     // Using "this" in ctor is a little fishy, but should work here at least as
      87             :     // long as there are no derivations:
      88           0 :     m_listener = new ChangesListener(*this);
      89             :     css::uno::Reference< css::beans::XMultiPropertySet > n(
      90             :         officecfg::Office::Common::Font::SourceViewFont::get(),
      91           0 :         css::uno::UNO_QUERY_THROW);
      92             :     {
      93           0 :         osl::MutexGuard g(m_mutex);
      94           0 :         m_notifier = n;
      95             :     }
      96           0 :     css::uno::Sequence< OUString > s(2);
      97           0 :     s[0] = "FontHeight";
      98           0 :     s[1] = "FontName";
      99           0 :     n->addPropertiesChangeListener(s, m_listener.get());
     100           0 :     m_ColorConfig.AddListener(this);
     101             : 
     102             :     //#i97044#
     103           0 :     EnableFocusSelectionHide( false );
     104           0 : }
     105             : 
     106           0 : OSqlEdit::~OSqlEdit()
     107             : {
     108           0 :     if (m_timerUndoActionCreation.IsActive())
     109           0 :         m_timerUndoActionCreation.Stop();
     110           0 :     css::uno::Reference< css::beans::XMultiPropertySet > n;
     111             :     {
     112           0 :         osl::MutexGuard g(m_mutex);
     113           0 :         n = m_notifier;
     114             :     }
     115           0 :     if (n.is()) {
     116           0 :         n->removePropertiesChangeListener(m_listener.get());
     117             :     }
     118           0 :     m_ColorConfig.RemoveListener(this);
     119           0 : }
     120             : 
     121           0 : void OSqlEdit::KeyInput( const KeyEvent& rKEvt )
     122             : {
     123           0 :     OJoinController& rController = m_pView->getContainerWindow()->getDesignView()->getController();
     124           0 :     rController.InvalidateFeature(SID_CUT);
     125           0 :     rController.InvalidateFeature(SID_COPY);
     126             : 
     127             :     // Is this a cut, copy, paste event?
     128           0 :     KeyFuncType aKeyFunc = rKEvt.GetKeyCode().GetFunction();
     129           0 :     if( (aKeyFunc==KeyFuncType::CUT)||(aKeyFunc==KeyFuncType::COPY)||(aKeyFunc==KeyFuncType::PASTE) )
     130           0 :         m_bAccelAction = true;
     131             : 
     132           0 :     MultiLineEditSyntaxHighlight::KeyInput( rKEvt );
     133             : 
     134           0 :     if( m_bAccelAction )
     135           0 :         m_bAccelAction = false;
     136           0 : }
     137             : 
     138             : 
     139           0 : void OSqlEdit::GetFocus()
     140             : {
     141           0 :     m_strOrigText  =GetText();
     142           0 :     MultiLineEditSyntaxHighlight::GetFocus();
     143           0 : }
     144             : 
     145           0 : IMPL_LINK_NOARG(OSqlEdit, OnUndoActionTimer)
     146             : {
     147           0 :     OUString aText = GetText();
     148           0 :     if(aText != m_strOrigText)
     149             :     {
     150           0 :         OJoinController& rController = m_pView->getContainerWindow()->getDesignView()->getController();
     151           0 :         SfxUndoManager& rUndoMgr = rController.GetUndoManager();
     152           0 :         OSqlEditUndoAct* pUndoAct = new OSqlEditUndoAct( this );
     153             : 
     154           0 :         pUndoAct->SetOriginalText( m_strOrigText );
     155           0 :         rUndoMgr.AddUndoAction( pUndoAct );
     156             : 
     157           0 :         rController.InvalidateFeature(SID_UNDO);
     158           0 :         rController.InvalidateFeature(SID_REDO);
     159             : 
     160           0 :         m_strOrigText  =aText;
     161             :     }
     162             : 
     163           0 :     return 0L;
     164             : }
     165             : 
     166           0 : IMPL_LINK_NOARG(OSqlEdit, OnInvalidateTimer)
     167             : {
     168           0 :     OJoinController& rController = m_pView->getContainerWindow()->getDesignView()->getController();
     169           0 :     rController.InvalidateFeature(SID_CUT);
     170           0 :     rController.InvalidateFeature(SID_COPY);
     171           0 :     if(!m_bStopTimer)
     172           0 :         m_timerInvalidate.Start();
     173           0 :     return 0L;
     174             : }
     175             : 
     176           0 : IMPL_LINK(OSqlEdit, ModifyHdl, void*, /*EMPTYTAG*/)
     177             : {
     178           0 :     if (m_timerUndoActionCreation.IsActive())
     179           0 :         m_timerUndoActionCreation.Stop();
     180           0 :     m_timerUndoActionCreation.Start();
     181             : 
     182           0 :     OJoinController& rController = m_pView->getContainerWindow()->getDesignView()->getController();
     183           0 :     if (!rController.isModified())
     184           0 :         rController.setModified( sal_True );
     185             : 
     186           0 :     rController.InvalidateFeature(SID_SBA_QRY_EXECUTE);
     187           0 :     rController.InvalidateFeature(SID_CUT);
     188           0 :     rController.InvalidateFeature(SID_COPY);
     189             : 
     190           0 :     m_lnkTextModifyHdl.Call(NULL);
     191           0 :     return 0;
     192             : }
     193             : 
     194           0 : void OSqlEdit::SetText(const OUString& rNewText)
     195             : {
     196           0 :     if (m_timerUndoActionCreation.IsActive())
     197             :     {   // create the trailing undo-actions
     198           0 :         m_timerUndoActionCreation.Stop();
     199           0 :         LINK(this, OSqlEdit, OnUndoActionTimer).Call(NULL);
     200             :     }
     201             : 
     202           0 :     MultiLineEditSyntaxHighlight::SetText(rNewText);
     203           0 :     m_strOrigText  =rNewText;
     204           0 : }
     205             : 
     206           0 : void OSqlEdit::stopTimer()
     207             : {
     208           0 :     m_bStopTimer = true;
     209           0 :     if (m_timerInvalidate.IsActive())
     210           0 :         m_timerInvalidate.Stop();
     211           0 : }
     212             : 
     213           0 : void OSqlEdit::startTimer()
     214             : {
     215           0 :     m_bStopTimer = false;
     216           0 :     if (!m_timerInvalidate.IsActive())
     217           0 :         m_timerInvalidate.Start();
     218           0 : }
     219             : 
     220           0 : void OSqlEdit::ConfigurationChanged( utl::ConfigurationBroadcaster* pOption, sal_uInt32 )
     221             : {
     222             :     assert( pOption == &m_ColorConfig );
     223             :     (void) pOption; // avoid warnings
     224           0 :     MultiLineEditSyntaxHighlight::UpdateData();
     225           0 : }
     226             : 
     227           0 : void OSqlEdit::ImplSetFont()
     228             : {
     229           0 :     AllSettings aSettings = GetSettings();
     230           0 :     StyleSettings aStyleSettings = aSettings.GetStyleSettings();
     231             :     OUString sFontName(
     232             :         officecfg::Office::Common::Font::SourceViewFont::FontName::get().
     233           0 :         get_value_or( OUString() ) );
     234           0 :     if ( sFontName.isEmpty() )
     235             :     {
     236           0 :         vcl::Font aTmpFont( OutputDevice::GetDefaultFont( DEFAULTFONT_FIXED, Application::GetSettings().GetUILanguageTag().getLanguageType(), 0 , this ) );
     237           0 :         sFontName = aTmpFont.GetName();
     238             :     }
     239             :     Size aFontSize(
     240           0 :         0, officecfg::Office::Common::Font::SourceViewFont::FontHeight::get() );
     241           0 :     vcl::Font aFont( sFontName, aFontSize );
     242           0 :     aStyleSettings.SetFieldFont(aFont);
     243           0 :     aSettings.SetStyleSettings(aStyleSettings);
     244           0 :     SetSettings(aSettings);
     245          72 : }
     246             : 
     247             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10