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

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * Version: MPL 1.1 / GPLv3+ / LGPLv3+
       4                 :            :  *
       5                 :            :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :            :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :            :  * the License or as specified alternatively below. You may obtain a copy of
       8                 :            :  * the License at http://www.mozilla.org/MPL/
       9                 :            :  *
      10                 :            :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :            :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :            :  * for the specific language governing rights and limitations under the
      13                 :            :  * License.
      14                 :            :  *
      15                 :            :  * Major Contributor(s):
      16                 :            :  * [ Copyright (C) 2011 August Sodora <augsod@gmail.com> (initial developer) ]
      17                 :            :  *
      18                 :            :  * All Rights Reserved.
      19                 :            :  *
      20                 :            :  * For minor contributions see the git repository.
      21                 :            :  *
      22                 :            :  * Alternatively, the contents of this file may be used under the terms of
      23                 :            :  * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
      24                 :            :  * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
      25                 :            :  * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
      26                 :            :  * instead of those above.
      27                 :            :  */
      28                 :            : 
      29                 :            : #include "baside2.hxx"
      30                 :            : #include "linenumberwindow.hxx"
      31                 :            : 
      32                 :            : #include <vcl/xtextedt.hxx>
      33                 :            : #include <vcl/textview.hxx>
      34                 :            : 
      35                 :          0 : LineNumberWindow::LineNumberWindow (Window* pParent, basctl::ModulWindow* pModulWindow) :
      36                 :            :     Window(pParent, WB_BORDER),
      37                 :            :     m_pModulWindow(pModulWindow),
      38                 :          0 :     m_nCurYOffset(0)
      39                 :            : {
      40                 :          0 :     SetBackground(Wallpaper(GetSettings().GetStyleSettings().GetFieldColor()));
      41                 :          0 :     m_nBaseWidth = GetTextWidth(rtl::OUString('8'));
      42                 :          0 :     m_nWidth = m_nBaseWidth * 3 + m_nBaseWidth / 2;
      43                 :          0 : }
      44                 :            : 
      45                 :          0 : LineNumberWindow::~LineNumberWindow() { }
      46                 :            : 
      47                 :          0 : void LineNumberWindow::Paint( const Rectangle& )
      48                 :            : {
      49                 :          0 :     if(SyncYOffset())
      50                 :          0 :         return;
      51                 :            : 
      52                 :          0 :     ExtTextEngine* txtEngine = m_pModulWindow->GetEditEngine();
      53                 :          0 :     if(!txtEngine)
      54                 :          0 :         return;
      55                 :            : 
      56                 :          0 :     TextView* txtView = m_pModulWindow->GetEditView();
      57                 :          0 :     if(!txtView)
      58                 :          0 :         return;
      59                 :            : 
      60                 :          0 :     GetParent()->Resize();
      61                 :            : 
      62                 :          0 :     int windowHeight = GetOutputSize().Height();
      63                 :          0 :     int nLineHeight = GetTextHeight();
      64                 :            : 
      65                 :          0 :     int startY = txtView->GetStartDocPos().Y();
      66                 :          0 :     int nStartLine = startY / nLineHeight + 1;
      67                 :          0 :     int nEndLine = (startY + windowHeight) / nLineHeight + 1;
      68                 :            : 
      69                 :          0 :     if(txtEngine->GetParagraphCount() + 1 < (unsigned int)nEndLine)
      70                 :          0 :         nEndLine = txtEngine->GetParagraphCount() + 1;
      71                 :            : 
      72                 :            :     // FIXME: it would be best if we could get notified of a font change
      73                 :            :     // rather than doing that re-calculation at each Paint event
      74                 :          0 :     m_nBaseWidth = GetTextWidth(rtl::OUString('8'));
      75                 :            : 
      76                 :            :     // reserve enough for 3 sigit minimum, with a bit to spare for confort
      77                 :          0 :     m_nWidth = m_nBaseWidth * 3 + m_nBaseWidth / 2;
      78                 :          0 :     int i = (nEndLine + 1) / 1000;
      79                 :          0 :     while(i)
      80                 :            :     {
      81                 :          0 :         i /= 10;
      82                 :          0 :         m_nWidth += m_nBaseWidth;
      83                 :            :     }
      84                 :            : 
      85                 :          0 :     sal_Int64 y = (nStartLine - 1) * nLineHeight;
      86                 :          0 :     for(sal_Int32 n = nStartLine; n <= nEndLine; ++n, y += nLineHeight)
      87                 :          0 :         DrawText(Point(0, y - m_nCurYOffset), rtl::OUString::valueOf(n));
      88                 :            : }
      89                 :            : 
      90                 :          0 : void LineNumberWindow::DataChanged(DataChangedEvent const & rDCEvt)
      91                 :            : {
      92                 :          0 :     Window::DataChanged(rDCEvt);
      93                 :          0 :     if (rDCEvt.GetType() == DATACHANGED_SETTINGS
      94                 :          0 :         && (rDCEvt.GetFlags() & SETTINGS_STYLE) != 0)
      95                 :            :     {
      96                 :          0 :         Color aColor(GetSettings().GetStyleSettings().GetFieldColor());
      97                 :          0 :         if (aColor != rDCEvt.GetOldSettings()->GetStyleSettings().GetFieldColor())
      98                 :            :         {
      99                 :          0 :             SetBackground(Wallpaper(aColor));
     100                 :          0 :             Invalidate();
     101                 :            :         }
     102                 :            :     }
     103                 :          0 : }
     104                 :            : 
     105                 :          0 : void LineNumberWindow::DoScroll(long nHorzScroll, long nVertScroll)
     106                 :            : {
     107                 :          0 :     m_nCurYOffset -= nVertScroll;
     108                 :          0 :     Window::Scroll(nHorzScroll, nVertScroll);
     109                 :          0 : }
     110                 :            : 
     111                 :          0 : long& LineNumberWindow::GetCurYOffset()
     112                 :            : {
     113                 :          0 :     return m_nCurYOffset;
     114                 :            : }
     115                 :            : 
     116                 :          0 : bool LineNumberWindow::SyncYOffset()
     117                 :            : {
     118                 :          0 :     TextView* pView = m_pModulWindow->GetEditView();
     119                 :          0 :     if (!pView)
     120                 :          0 :         return false;
     121                 :            : 
     122                 :          0 :     long nViewYOffset = pView->GetStartDocPos().Y();
     123                 :          0 :     if (m_nCurYOffset == nViewYOffset)
     124                 :          0 :         return false;
     125                 :            : 
     126                 :          0 :     m_nCurYOffset = nViewYOffset;
     127                 :          0 :     Invalidate();
     128                 :          0 :     return true;
     129                 :            : }
     130                 :            : 
     131                 :          0 : int LineNumberWindow::GetWidth()
     132                 :            : {
     133                 :          0 :     return m_nWidth;
     134                 :            : }
     135                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10