LCOV - code coverage report
Current view: top level - dbaccess/source/ui/control - sqledit.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 122 0.0 %
Date: 2012-08-25 Functions: 0 22 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 228 0.0 %

           Branch data     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                 :            : 
      38                 :            : namespace css = ::com::sun::star;
      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)
      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)
      60                 :            :     {
      61         [ #  # ]:          0 :         SolarMutexGuard g;
      62 [ #  # ][ #  # ]:          0 :         editor_.ImplSetFont();
      63                 :          0 :     }
      64                 :            : 
      65                 :            :     OSqlEdit & editor_;
      66                 :            : };
      67                 :            : 
      68                 :            : DBG_NAME(OSqlEdit)
      69                 :          0 : OSqlEdit::OSqlEdit( OQueryTextView* pParent,  WinBits nWinStyle ) :
      70                 :            :     MultiLineEditSyntaxHighlight( pParent, nWinStyle )
      71                 :            :     ,m_pView(pParent)
      72                 :            :     ,m_bAccelAction( sal_False )
      73 [ #  # ][ #  # ]:          0 :     ,m_bStopTimer(sal_False )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      74                 :            : {
      75                 :            :     DBG_CTOR(OSqlEdit,NULL);
      76         [ #  # ]:          0 :     SetHelpId( HID_CTL_QRYSQLEDIT );
      77         [ #  # ]:          0 :     SetModifyHdl( LINK(this, OSqlEdit, ModifyHdl) );
      78                 :            : 
      79         [ #  # ]:          0 :     m_timerUndoActionCreation.SetTimeout(1000);
      80         [ #  # ]:          0 :     m_timerUndoActionCreation.SetTimeoutHdl(LINK(this, OSqlEdit, OnUndoActionTimer));
      81                 :            : 
      82         [ #  # ]:          0 :     m_timerInvalidate.SetTimeout(200);
      83         [ #  # ]:          0 :     m_timerInvalidate.SetTimeoutHdl(LINK(this, OSqlEdit, OnInvalidateTimer));
      84         [ #  # ]:          0 :     m_timerInvalidate.Start();
      85                 :            : 
      86         [ #  # ]:          0 :     ImplSetFont();
      87                 :            :     // Listen for change of Font and Color Settings:
      88                 :            :     // Using "this" in ctor is a little fishy, but should work here at least as
      89                 :            :     // long as there are no derivations:
      90 [ #  # ][ #  # ]:          0 :     m_listener = new ChangesListener(*this);
      91                 :            :     css::uno::Reference< css::beans::XMultiPropertySet > n(
      92                 :            :         officecfg::Office::Common::Font::SourceViewFont::get(),
      93 [ #  # ][ #  # ]:          0 :         css::uno::UNO_QUERY_THROW);
                 [ #  # ]
      94                 :            :     {
      95         [ #  # ]:          0 :         osl::MutexGuard g(m_mutex);
      96 [ #  # ][ #  # ]:          0 :         m_notifier = n;
      97                 :            :     }
      98         [ #  # ]:          0 :     css::uno::Sequence< rtl::OUString > s(2);
      99 [ #  # ][ #  # ]:          0 :     s[0] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FontHeight"));
     100 [ #  # ][ #  # ]:          0 :     s[1] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FontName"));
     101 [ #  # ][ #  # ]:          0 :     n->addPropertiesChangeListener(s, m_listener.get());
         [ #  # ][ #  # ]
     102         [ #  # ]:          0 :     m_ColorConfig.AddListener(this);
     103                 :            : 
     104                 :            :     //#i97044#
     105 [ #  # ][ #  # ]:          0 :     EnableFocusSelectionHide( sal_False );
     106                 :          0 : }
     107                 :            : 
     108 [ #  # ][ #  # ]:          0 : OSqlEdit::~OSqlEdit()
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     109                 :            : {
     110                 :            :     DBG_DTOR(OSqlEdit,NULL);
     111         [ #  # ]:          0 :     if (m_timerUndoActionCreation.IsActive())
     112         [ #  # ]:          0 :         m_timerUndoActionCreation.Stop();
     113                 :          0 :     css::uno::Reference< css::beans::XMultiPropertySet > n;
     114                 :            :     {
     115         [ #  # ]:          0 :         osl::MutexGuard g(m_mutex);
     116 [ #  # ][ #  # ]:          0 :         n = m_notifier;
     117                 :            :     }
     118         [ #  # ]:          0 :     if (n.is()) {
     119 [ #  # ][ #  # ]:          0 :         n->removePropertiesChangeListener(m_listener.get());
         [ #  # ][ #  # ]
     120                 :            :     }
     121         [ #  # ]:          0 :     m_ColorConfig.RemoveListener(this);
     122         [ #  # ]:          0 : }
     123                 :            : 
     124                 :          0 : void OSqlEdit::KeyInput( const KeyEvent& rKEvt )
     125                 :            : {
     126                 :            :     DBG_CHKTHIS(OSqlEdit,NULL);
     127                 :          0 :     OJoinController& rController = m_pView->getContainerWindow()->getDesignView()->getController();
     128         [ #  # ]:          0 :     rController.InvalidateFeature(SID_CUT);
     129         [ #  # ]:          0 :     rController.InvalidateFeature(SID_COPY);
     130                 :            : 
     131                 :            :     // Is this a cut, copy, paste event?
     132                 :          0 :     KeyFuncType aKeyFunc = rKEvt.GetKeyCode().GetFunction();
     133 [ #  # ][ #  # ]:          0 :     if( (aKeyFunc==KEYFUNC_CUT)||(aKeyFunc==KEYFUNC_COPY)||(aKeyFunc==KEYFUNC_PASTE) )
                 [ #  # ]
     134                 :          0 :         m_bAccelAction = sal_True;
     135                 :            : 
     136                 :          0 :     MultiLineEditSyntaxHighlight::KeyInput( rKEvt );
     137                 :            : 
     138         [ #  # ]:          0 :     if( m_bAccelAction )
     139                 :          0 :         m_bAccelAction = sal_False;
     140                 :          0 : }
     141                 :            : 
     142                 :          0 : sal_Bool OSqlEdit::IsInAccelAct()
     143                 :            : {
     144                 :            :     DBG_CHKTHIS(OSqlEdit,NULL);
     145                 :            :     // Cut, Copy, Paste by Accel. runs the action in the Edit but also the
     146                 :            :     // corresponding slot in the View. Therefore, the action occurs twice.
     147                 :            :     // To prevent this, SlotExec in View can call this function.
     148                 :            : 
     149                 :          0 :     return m_bAccelAction;
     150                 :            : }
     151                 :            : 
     152                 :          0 : void OSqlEdit::GetFocus()
     153                 :            : {
     154                 :            :     DBG_CHKTHIS(OSqlEdit,NULL);
     155         [ #  # ]:          0 :     m_strOrigText  =GetText();
     156                 :          0 :     MultiLineEditSyntaxHighlight::GetFocus();
     157                 :          0 : }
     158                 :            : 
     159                 :          0 : IMPL_LINK_NOARG(OSqlEdit, OnUndoActionTimer)
     160                 :            : {
     161         [ #  # ]:          0 :     String aText  =GetText();
     162 [ #  # ][ #  # ]:          0 :     if(aText != m_strOrigText)
     163                 :            :     {
     164         [ #  # ]:          0 :         OJoinController& rController = m_pView->getContainerWindow()->getDesignView()->getController();
     165         [ #  # ]:          0 :         SfxUndoManager& rUndoMgr = rController.GetUndoManager();
     166 [ #  # ][ #  # ]:          0 :         OSqlEditUndoAct* pUndoAct = new OSqlEditUndoAct( this );
     167                 :            : 
     168         [ #  # ]:          0 :         pUndoAct->SetOriginalText( m_strOrigText );
     169         [ #  # ]:          0 :         rUndoMgr.AddUndoAction( pUndoAct );
     170                 :            : 
     171 [ #  # ][ #  # ]:          0 :         rController.InvalidateFeature(SID_UNDO);
     172 [ #  # ][ #  # ]:          0 :         rController.InvalidateFeature(SID_REDO);
     173                 :            : 
     174         [ #  # ]:          0 :         m_strOrigText  =aText;
     175                 :            :     }
     176                 :            : 
     177         [ #  # ]:          0 :     return 0L;
     178                 :            : }
     179                 :            : 
     180                 :          0 : IMPL_LINK_NOARG(OSqlEdit, OnInvalidateTimer)
     181                 :            : {
     182                 :          0 :     OJoinController& rController = m_pView->getContainerWindow()->getDesignView()->getController();
     183         [ #  # ]:          0 :     rController.InvalidateFeature(SID_CUT);
     184         [ #  # ]:          0 :     rController.InvalidateFeature(SID_COPY);
     185         [ #  # ]:          0 :     if(!m_bStopTimer)
     186                 :          0 :         m_timerInvalidate.Start();
     187                 :          0 :     return 0L;
     188                 :            : }
     189                 :            : 
     190                 :          0 : IMPL_LINK(OSqlEdit, ModifyHdl, void*, /*EMPTYTAG*/)
     191                 :            : {
     192         [ #  # ]:          0 :     if (m_timerUndoActionCreation.IsActive())
     193                 :          0 :         m_timerUndoActionCreation.Stop();
     194                 :          0 :     m_timerUndoActionCreation.Start();
     195                 :            : 
     196                 :          0 :     OJoinController& rController = m_pView->getContainerWindow()->getDesignView()->getController();
     197         [ #  # ]:          0 :     if (!rController.isModified())
     198                 :          0 :         rController.setModified( sal_True );
     199                 :            : 
     200         [ #  # ]:          0 :     rController.InvalidateFeature(SID_SBA_QRY_EXECUTE);
     201         [ #  # ]:          0 :     rController.InvalidateFeature(SID_CUT);
     202         [ #  # ]:          0 :     rController.InvalidateFeature(SID_COPY);
     203                 :            : 
     204                 :          0 :     m_lnkTextModifyHdl.Call(NULL);
     205                 :          0 :     return 0;
     206                 :            : }
     207                 :            : 
     208                 :          0 : void OSqlEdit::SetText(const String& rNewText)
     209                 :            : {
     210                 :            :     DBG_CHKTHIS(OSqlEdit,NULL);
     211         [ #  # ]:          0 :     if (m_timerUndoActionCreation.IsActive())
     212                 :            :     {   // create the trailing undo-actions
     213                 :          0 :         m_timerUndoActionCreation.Stop();
     214         [ #  # ]:          0 :         LINK(this, OSqlEdit, OnUndoActionTimer).Call(NULL);
     215                 :            :     }
     216                 :            : 
     217                 :          0 :     MultiLineEditSyntaxHighlight::SetText(rNewText);
     218                 :          0 :     m_strOrigText  =rNewText;
     219                 :          0 : }
     220                 :            : 
     221                 :          0 : void OSqlEdit::stopTimer()
     222                 :            : {
     223                 :          0 :     m_bStopTimer = sal_True;
     224         [ #  # ]:          0 :     if (m_timerInvalidate.IsActive())
     225                 :          0 :         m_timerInvalidate.Stop();
     226                 :          0 : }
     227                 :            : 
     228                 :          0 : void OSqlEdit::startTimer()
     229                 :            : {
     230                 :          0 :     m_bStopTimer = sal_False;
     231         [ #  # ]:          0 :     if (!m_timerInvalidate.IsActive())
     232                 :          0 :         m_timerInvalidate.Start();
     233                 :          0 : }
     234                 :            : 
     235                 :          0 : void OSqlEdit::ConfigurationChanged( utl::ConfigurationBroadcaster* pOption, sal_uInt32 )
     236                 :            : {
     237                 :            :     assert( pOption == &m_ColorConfig );
     238                 :            :     (void) pOption; // avoid warnings
     239                 :          0 :     MultiLineEditSyntaxHighlight::UpdateData();
     240                 :          0 : }
     241                 :            : 
     242                 :          0 : void OSqlEdit::ImplSetFont()
     243                 :            : {
     244         [ #  # ]:          0 :     AllSettings aSettings = GetSettings();
     245         [ #  # ]:          0 :     StyleSettings aStyleSettings = aSettings.GetStyleSettings();
     246                 :            :     rtl::OUString sFontName(
     247                 :            :         officecfg::Office::Common::Font::SourceViewFont::FontName::get().
     248 [ #  # ][ #  # ]:          0 :         get_value_or( rtl::OUString() ) );
         [ #  # ][ #  # ]
     249         [ #  # ]:          0 :     if ( sFontName.isEmpty() )
     250                 :            :     {
     251 [ #  # ][ #  # ]:          0 :         Font aTmpFont( OutputDevice::GetDefaultFont( DEFAULTFONT_FIXED, Application::GetSettings().GetUILanguage(), 0 , this ) );
                 [ #  # ]
     252 [ #  # ][ #  # ]:          0 :         sFontName = aTmpFont.GetName();
                 [ #  # ]
     253                 :            :     }
     254                 :            :     Size aFontSize(
     255                 :          0 :         0, officecfg::Office::Common::Font::SourceViewFont::FontHeight::get() );
     256 [ #  # ][ #  # ]:          0 :     Font aFont( sFontName, aFontSize );
                 [ #  # ]
     257         [ #  # ]:          0 :     aStyleSettings.SetFieldFont(aFont);
     258         [ #  # ]:          0 :     aSettings.SetStyleSettings(aStyleSettings);
     259 [ #  # ][ #  # ]:          0 :     SetSettings(aSettings);
         [ #  # ][ #  # ]
     260                 :          0 : }
     261                 :            : 
     262                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10