LCOV - code coverage report
Current view: top level - svtools/source/edit - editsyntaxhighlighter.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 92 0.0 %
Date: 2012-08-25 Functions: 0 9 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 142 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <svtools/svmedit.hxx>
      31                 :            : #include <vcl/xtextedt.hxx>
      32                 :            : #include <svtools/editsyntaxhighlighter.hxx>
      33                 :            : #include <vcl/txtattr.hxx>
      34                 :            : 
      35                 :            : 
      36                 :          0 : MultiLineEditSyntaxHighlight::MultiLineEditSyntaxHighlight( Window* pParent, WinBits nWinStyle,
      37 [ #  # ][ #  # ]:          0 :     HighlighterLanguage aLanguage): MultiLineEdit(pParent,nWinStyle), mbDoBracketHilight(true)
      38                 :            : {
      39         [ #  # ]:          0 :     EnableUpdateData(300);
      40         [ #  # ]:          0 :     aHighlighter.initialize( aLanguage );
      41                 :          0 : }
      42                 :            : 
      43                 :          0 : MultiLineEditSyntaxHighlight::MultiLineEditSyntaxHighlight( Window* pParent, const ResId& rResId ,
      44 [ #  # ][ #  # ]:          0 :     HighlighterLanguage aLanguage): MultiLineEdit(pParent,rResId), mbDoBracketHilight(true)
      45                 :            : {
      46         [ #  # ]:          0 :     EnableUpdateData(300);
      47         [ #  # ]:          0 :     aHighlighter.initialize( aLanguage );
      48                 :          0 : }
      49                 :            : 
      50 [ #  # ][ #  # ]:          0 : MultiLineEditSyntaxHighlight::~MultiLineEditSyntaxHighlight()
      51                 :            : {
      52         [ #  # ]:          0 : }
      53                 :            : 
      54                 :          0 : void MultiLineEditSyntaxHighlight::SetText(const String& rNewText)
      55                 :            : {
      56                 :          0 :     MultiLineEdit::SetText(rNewText);
      57                 :          0 :     UpdateData();
      58                 :          0 : }
      59                 :            : 
      60                 :          0 : void MultiLineEditSyntaxHighlight::DoBracketHilight(sal_uInt16 aKey)
      61                 :            : {
      62 [ #  # ][ #  # ]:          0 :     TextSelection aCurrentPos = GetTextView()->GetSelection();
      63                 :          0 :     xub_StrLen aStartPos  = aCurrentPos.GetStart().GetIndex();
      64                 :          0 :     sal_uLong nStartPara = aCurrentPos.GetStart().GetPara();
      65                 :          0 :     sal_uInt16 aCount = 0;
      66                 :          0 :     int aChar = -1;
      67                 :            : 
      68   [ #  #  #  #  :          0 :     switch (aKey)
                      # ]
      69                 :            :     {
      70                 :            :         case '\'':  // no break
      71                 :            :         case '"':
      72                 :            :         {
      73                 :          0 :             aChar = aKey;
      74                 :          0 :             break;
      75                 :            :         }
      76                 :            :         case '}' :
      77                 :            :         {
      78                 :          0 :             aChar = '{';
      79                 :          0 :             break;
      80                 :            :         }
      81                 :            :         case ')':
      82                 :            :         {
      83                 :          0 :             aChar = '(';
      84                 :          0 :             break;
      85                 :            :         }
      86                 :            :         case ']':
      87                 :            :         {
      88                 :          0 :             aChar = '[';
      89                 :          0 :             break;
      90                 :            :         }
      91                 :            :     }
      92                 :            : 
      93         [ #  # ]:          0 :     if (aChar != -1)
      94                 :            :     {
      95         [ #  # ]:          0 :         for (long aPara =nStartPara; aPara>=0;--aPara)
      96                 :            :         {
      97         [ #  # ]:          0 :             if ( aStartPos == 0 )
      98                 :          0 :                 continue;
      99                 :            : 
     100 [ #  # ][ #  # ]:          0 :             String aLine( GetTextEngine()->GetText( aPara ) );
     101 [ #  # ][ #  # ]:          0 :             for (sal_uInt16 i = ((unsigned long)aPara==nStartPara) ? aStartPos-1 : (sal_uInt16)(aLine.Len()-1); i>0; --i)
     102                 :            :             {
     103         [ #  # ]:          0 :                 if (aLine.GetChar(i)==aChar)
     104                 :            :                 {
     105         [ #  # ]:          0 :                     if (!aCount)
     106                 :            :                     {
     107 [ #  # ][ #  # ]:          0 :                         GetTextEngine()->SetAttrib( TextAttribFontWeight( WEIGHT_ULTRABOLD ), aPara, i, i+1, sal_True );
         [ #  # ][ #  # ]
     108 [ #  # ][ #  # ]:          0 :                         GetTextEngine()->SetAttrib( TextAttribFontColor( Color(0,0,0) ), aPara, i, i+1, sal_True );
         [ #  # ][ #  # ]
     109 [ #  # ][ #  # ]:          0 :                         GetTextEngine()->SetAttrib( TextAttribFontWeight( WEIGHT_ULTRABOLD ), nStartPara, aStartPos, aStartPos, sal_True );
         [ #  # ][ #  # ]
     110 [ #  # ][ #  # ]:          0 :                         GetTextEngine()->SetAttrib( TextAttribFontColor( Color(0,0,0) ), nStartPara, aStartPos, aStartPos, sal_True );
         [ #  # ][ #  # ]
     111                 :          0 :                         return;
     112                 :            :                     }
     113                 :            :                     else
     114                 :          0 :                         aCount--;
     115                 :            :                 }
     116         [ #  # ]:          0 :                 if (aLine.GetChar(i)==aKey)
     117                 :          0 :                     aCount++;
     118                 :            :             }
     119 [ #  # ][ #  # ]:          0 :         }
     120                 :            :     }
     121                 :            : }
     122                 :            : 
     123                 :          0 : long MultiLineEditSyntaxHighlight::PreNotify( NotifyEvent& rNEvt )
     124                 :            : {
     125 [ #  # ][ #  # ]:          0 :     if ( mbDoBracketHilight && (rNEvt.GetType() == EVENT_KEYINPUT) )
                 [ #  # ]
     126                 :          0 :         DoBracketHilight(rNEvt.GetKeyEvent()->GetCharCode());
     127                 :            : 
     128                 :          0 :     return MultiLineEdit::PreNotify(rNEvt);
     129                 :            : }
     130                 :            : 
     131                 :          0 : Color MultiLineEditSyntaxHighlight::GetColorValue(TokenTypes aToken)
     132                 :            : {
     133                 :          0 :     Color aColor;
     134      [ #  #  # ]:          0 :     switch (aHighlighter.GetLanguage())
     135                 :            :     {
     136                 :            :         case HIGHLIGHT_SQL:
     137                 :            :         {
     138   [ #  #  #  #  :          0 :             switch (aToken)
             #  #  #  # ]
     139                 :            :             {
     140                 :          0 :                 case TT_IDENTIFIER: aColor = (ColorData)m_aColorConfig.GetColorValue(svtools::SQLIDENTIFIER).nColor; break;
     141                 :          0 :                 case TT_NUMBER:     aColor = (ColorData)m_aColorConfig.GetColorValue(svtools::SQLNUMBER).nColor; break;
     142                 :          0 :                 case TT_STRING:     aColor = (ColorData)m_aColorConfig.GetColorValue(svtools::SQLSTRING).nColor; break;
     143                 :          0 :                 case TT_OPERATOR:   aColor = (ColorData)m_aColorConfig.GetColorValue(svtools::SQLOPERATOR).nColor; break;
     144                 :          0 :                 case TT_KEYWORDS:   aColor = (ColorData)m_aColorConfig.GetColorValue(svtools::SQLKEYWORD).nColor; break;
     145                 :          0 :                 case TT_PARAMETER:  aColor = (ColorData)m_aColorConfig.GetColorValue(svtools::SQLPARAMETER).nColor; break;
     146                 :          0 :                 case TT_COMMENT:    aColor = (ColorData)m_aColorConfig.GetColorValue(svtools::SQLCOMMENT).nColor; break;
     147                 :          0 :                 default:            aColor = Color(0,0,0);
     148                 :            :             }
     149                 :          0 :             break;
     150                 :            :         }
     151                 :            :         case HIGHLIGHT_BASIC:
     152                 :            :         {
     153   [ #  #  #  #  :          0 :             switch (aToken)
             #  #  #  # ]
     154                 :            :             {
     155                 :          0 :                 case TT_IDENTIFIER: aColor = Color(255,0,0); break;
     156                 :          0 :                 case TT_COMMENT:    aColor = Color(0,0,45); break;
     157                 :          0 :                 case TT_NUMBER:     aColor = Color(204,102,204); break;
     158                 :          0 :                 case TT_STRING:     aColor = Color(0,255,45); break;
     159                 :          0 :                 case TT_OPERATOR:   aColor = Color(0,0,100); break;
     160                 :          0 :                 case TT_KEYWORDS:   aColor = Color(0,0,255); break;
     161                 :          0 :                 case TT_ERROR :     aColor = Color(0,255,255); break;
     162                 :          0 :                 default:            aColor = Color(0,0,0);
     163                 :            :             }
     164                 :          0 :             break;
     165                 :            :         }
     166                 :          0 :         default: aColor = Color(0,0,0);
     167                 :            : 
     168                 :            :     }
     169                 :          0 :     return aColor;
     170                 :            : }
     171                 :            : 
     172                 :          0 : void MultiLineEditSyntaxHighlight::UpdateData()
     173                 :            : {
     174                 :            :     // syntax highlighting
     175                 :            :     // this must be possible improved by using notifychange correctly
     176                 :          0 :     sal_Bool bTempModified = GetTextEngine()->IsModified();
     177         [ #  # ]:          0 :     for (unsigned int nLine=0; nLine < GetTextEngine()->GetParagraphCount(); nLine++)
     178                 :            :     {
     179 [ #  # ][ #  # ]:          0 :         String aLine( GetTextEngine()->GetText( nLine ) );
     180         [ #  # ]:          0 :         aHighlighter.notifyChange( nLine, 0, &aLine, 1 );
     181                 :            : 
     182 [ #  # ][ #  # ]:          0 :         GetTextEngine()->RemoveAttribs( nLine, sal_True );
     183         [ #  # ]:          0 :         HighlightPortions aPortions;
     184         [ #  # ]:          0 :         aHighlighter.getHighlightPortions( nLine, aLine, aPortions );
     185         [ #  # ]:          0 :         for ( size_t i = 0; i < aPortions.size(); i++ )
     186                 :            :         {
     187                 :          0 :             HighlightPortion& r = aPortions[i];
     188 [ #  # ][ #  # ]:          0 :             GetTextEngine()->SetAttrib( TextAttribFontColor( GetColorValue(r.tokenType) ), nLine, r.nBegin, r.nEnd, sal_True );
         [ #  # ][ #  # ]
                 [ #  # ]
     189                 :            :         }
     190         [ #  # ]:          0 :     }
     191                 :          0 :     GetTextView()->ShowCursor( false, true );
     192                 :          0 :     GetTextEngine()->SetModified(bTempModified);
     193                 :          0 : }
     194                 :            : 
     195                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10