LCOV - code coverage report
Current view: top level - basctl/source/basicide - linenumberwindow.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 64 0.0 %
Date: 2014-04-14 Functions: 0 9 0.0 %
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             : 
      10             : #include "baside2.hxx"
      11             : #include "linenumberwindow.hxx"
      12             : 
      13             : #include <vcl/xtextedt.hxx>
      14             : #include <vcl/textview.hxx>
      15             : #include <vcl/settings.hxx>
      16             : 
      17             : namespace basctl
      18             : {
      19             : 
      20           0 : LineNumberWindow::LineNumberWindow (Window* pParent, ModulWindow* pModulWindow) :
      21             :     Window(pParent, WB_BORDER),
      22             :     m_pModulWindow(pModulWindow),
      23           0 :     m_nCurYOffset(0)
      24             : {
      25           0 :     SetBackground(Wallpaper(GetSettings().GetStyleSettings().GetFieldColor()));
      26           0 :     m_nBaseWidth = GetTextWidth("8");
      27           0 :     m_nWidth = m_nBaseWidth * 3 + m_nBaseWidth / 2;
      28           0 : }
      29             : 
      30           0 : LineNumberWindow::~LineNumberWindow()
      31           0 : { }
      32             : 
      33           0 : void LineNumberWindow::Paint( const Rectangle& )
      34             : {
      35           0 :     if(SyncYOffset())
      36           0 :         return;
      37             : 
      38           0 :     ExtTextEngine* txtEngine = m_pModulWindow->GetEditEngine();
      39           0 :     if(!txtEngine)
      40           0 :         return;
      41             : 
      42           0 :     TextView* txtView = m_pModulWindow->GetEditView();
      43           0 :     if(!txtView)
      44           0 :         return;
      45             : 
      46           0 :     GetParent()->Resize();
      47             : 
      48           0 :     int windowHeight = GetOutputSize().Height();
      49           0 :     int nLineHeight = GetTextHeight();
      50           0 :     if(!nLineHeight)
      51             :     {
      52           0 :         return;
      53             :     }
      54             : 
      55           0 :     int startY = txtView->GetStartDocPos().Y();
      56           0 :     int nStartLine = startY / nLineHeight + 1;
      57           0 :     int nEndLine = (startY + windowHeight) / nLineHeight + 1;
      58             : 
      59           0 :     if(txtEngine->GetParagraphCount() + 1 < (unsigned int)nEndLine)
      60           0 :         nEndLine = txtEngine->GetParagraphCount() + 1;
      61             : 
      62             :     // FIXME: it would be best if we could get notified of a font change
      63             :     // rather than doing that re-calculation at each Paint event
      64           0 :     m_nBaseWidth = GetTextWidth("8");
      65             : 
      66             :     // reserve enough for 3 sigit minimum, with a bit to spare for confort
      67           0 :     m_nWidth = m_nBaseWidth * 3 + m_nBaseWidth / 2;
      68           0 :     int i = (nEndLine + 1) / 1000;
      69           0 :     while(i)
      70             :     {
      71           0 :         i /= 10;
      72           0 :         m_nWidth += m_nBaseWidth;
      73             :     }
      74             : 
      75           0 :     sal_Int64 y = (nStartLine - 1) * (sal_Int64)nLineHeight;
      76           0 :     for(sal_Int32 n = nStartLine; n <= nEndLine; ++n, y += nLineHeight)
      77           0 :         DrawText(Point(0, y - m_nCurYOffset), OUString::number(n));
      78             : }
      79             : 
      80           0 : void LineNumberWindow::DataChanged(DataChangedEvent const & rDCEvt)
      81             : {
      82           0 :     Window::DataChanged(rDCEvt);
      83           0 :     if (rDCEvt.GetType() == DATACHANGED_SETTINGS
      84           0 :         && (rDCEvt.GetFlags() & SETTINGS_STYLE) != 0)
      85             :     {
      86           0 :         Color aColor(GetSettings().GetStyleSettings().GetFieldColor());
      87           0 :         const AllSettings* pOldSettings = rDCEvt.GetOldSettings();
      88           0 :         if (!pOldSettings || aColor != pOldSettings->GetStyleSettings().GetFieldColor())
      89             :         {
      90           0 :             SetBackground(Wallpaper(aColor));
      91           0 :             Invalidate();
      92             :         }
      93             :     }
      94           0 : }
      95             : 
      96           0 : void LineNumberWindow::DoScroll(long nHorzScroll, long nVertScroll)
      97             : {
      98           0 :     m_nCurYOffset -= nVertScroll;
      99           0 :     Window::Scroll(nHorzScroll, nVertScroll);
     100           0 : }
     101             : 
     102           0 : long& LineNumberWindow::GetCurYOffset()
     103             : {
     104           0 :     return m_nCurYOffset;
     105             : }
     106             : 
     107           0 : bool LineNumberWindow::SyncYOffset()
     108             : {
     109           0 :     TextView* pView = m_pModulWindow->GetEditView();
     110           0 :     if (!pView)
     111           0 :         return false;
     112             : 
     113           0 :     long nViewYOffset = pView->GetStartDocPos().Y();
     114           0 :     if (m_nCurYOffset == nViewYOffset)
     115           0 :         return false;
     116             : 
     117           0 :     m_nCurYOffset = nViewYOffset;
     118           0 :     Invalidate();
     119           0 :     return true;
     120             : }
     121             : 
     122           0 : int LineNumberWindow::GetWidth()
     123             : {
     124           0 :     return m_nWidth;
     125             : }
     126             : 
     127             : } // namespace basctl
     128             : 
     129             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10