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

Generated by: LCOV version 1.11